我有一个动态 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;
//...
}
最佳答案
我能够通过添加以下 curl 选项来实现它:
curl_setopt($curly[$id], CURLOPT_HTTPAUTH, CURLAUTH_NTLM);
curl_setopt($curly[$id], CURLOPT_UNRESTRICTED_AUTH, true);
curl_setopt($curly[$id], CURLOPT_USERPWD, ":");
根据 php 的版本,有一个 bug:https://bugs.php.net/bug.php?id=62195
关于php:将 ntlm 凭据转发到 curl,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9111705/