我在 CURL 上的标头有问题,我的脚本有两部分,第一部分是认证,第二部分是请求,第一部分运行良好,我得到了结果代码和一个 id,在我设置的第二部分使用该 id 设置标头并将其发送到标头上,但我收到此错误(< HTTP/1.1 401 Unauthorized),但是,我现在尝试使用 firefox 插件(ModifyHeaders),现在得到响应(我在这个软件上设置了 id 并通过 URL 访问 WS),我不知道发生了什么或如何修复它,这里是代码:
$postargs = array('username' => 'user', 'password' => 'pass', 'key' => '1234567890');
$postargs = json_encode($postargs);
$ch = curl_init();
curl_setopt($ch, CURLOPT_POST, TRUE);
curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-Type: application/json; charset=utf-8","Accept:application/json, text/javascript, */*; q=0.01"));
curl_setopt($ch, CURLOPT_POSTFIELDS, $postargs);
curl_setopt($ch, CURLOPT_URL, "https://ws.com/login");
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_HTTPPROXYTUNNEL, 0);
curl_setopt($ch, CURLOPT_VERBOSE, TRUE);
$fh = fopen('curl_debug.txt', 'w');
curl_setopt($ch, CURLOPT_STDERR, $fh);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
$response = curl_exec($ch);
$a = json_decode($response);
echo $a->result;
curl_close($ch);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://ws.com/data");
curl_setopt($ch, CURLOPT_HTTPHEADER, array("id : $a->result","dataRequest : name","Content-Type: application/json; charset=utf-8","Accept:application/json, text/javascript, */*; q=0.01"));
curl_setopt($ch, CURLOPT_VERBOSE, TRUE);
curl_setopt ($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_HTTPPROXYTUNNEL, 0);
$fh2 = fopen('curl_debug2.txt', 'w');
curl_setopt($ch, CURLOPT_STDERR, $fh2);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
$response2 = curl_exec($ch);
脚本有什么问题?为什么标头(在本例中为 id)不是由脚本执行,而是由 ModifyHeaders 执行?
提前致谢。