我有一个动态 php 页面,我需要使用 get 参数来调用它。然后我想将生成的 html 放入一个字符串中并稍后使用它(我正在尝试用于 Web 服务的 tonic 框架)
所以这类似于PHP - 将动态生成(和回显)的 HTML 读取到字符串中? https://stackoverflow.com/questions/1245438/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_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 https://bugs.php.net/bug.php?id=62195
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)