【发布时间】:2012-02-02 11:40:42
【问题描述】:
我有一个动态 php 页面,我需要使用 get 参数调用它。然后我想将生成的 html 放入一个字符串中并稍后使用它(我正在尝试为 Web 服务提供 tonic 框架)
所以这类似于PHP - Read dynamically generated (and echoed) HTML into a string?,我尝试了使用 cURL 的答案。
问题是身份验证是使用 ntlm (apache mod_auth_sspi) 完成的。执行 curl 的 php 脚本已经过身份验证,例如只有有效用户才能执行它。以某种方式可以将这些“凭据”传递给 cURL? (用户名可用,但当然不是密码)
或者完全不同的方法也可以,但我唯一的想法是创建一个函数来创建带有 html 内容的字符串。
$response = new Response($request);
$format = $request->mostAcceptable(array(
'json', 'html', 'txt'
));
switch ($format) {
case 'html':
$response->addHeader('Content-type', 'text/html');
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'http://localhost/viewRecord.php?identifier=' . $identifier);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_NTLM);
$html = curl_exec($ch);
curl_close($ch);
$response->body = $html;
break;
//...
}
【问题讨论】: