我有一个动态php页面,我需要使用get参数来调用它。然后,我想将生成的html放入字符串中,并在以后使用(我正在尝试使用Web服务的补品框架)
因此,这类似于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的版本:https://bugs.php.net/bug.php?id=62195