Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/255.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
php curl-通过http身份验证访问url(需要帮助)_Php_Authentication_Curl - Fatal编程技术网

php curl-通过http身份验证访问url(需要帮助)

php curl-通过http身份验证访问url(需要帮助),php,authentication,curl,Php,Authentication,Curl,我在HTTP身份验证中遇到问题。我无法获取此url的内容,因为它需要http身份验证 代码: 步骤2 URL: GET https://www.ssoauth.com/obrareq.cgi?wh=xxx wu=xxx wo=xxx rh=http://www.abcdefg.com ru=/12345/ Status: 302 Redirect Protocol: https 步骤3 URL: GET http://www.abcdefg.com/obrar.cgi?cookie=xxxxx

我在HTTP身份验证中遇到问题。我无法获取此url的内容,因为它需要http身份验证

代码:

步骤2

URL: GET https://www.ssoauth.com/obrareq.cgi?wh=xxx wu=xxx wo=xxx rh=http://www.abcdefg.com ru=/12345/
Status: 302 Redirect
Protocol: https
步骤3

URL: GET http://www.abcdefg.com/obrar.cgi?cookie=xxxxxxxxxxxxxxx
Status: 302 Found
Protocol: http
步骤4

URL: GET http://www.abcdefg.com/12345/
Status: 200 OK
Protocol: http
然后显示内容

这和饼干有关吗? 如何使用php curl读取内容?

您必须设置:

curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);

这将使cURL服从302并生成一个额外的请求。

我刚刚添加了cURL\u setopt($ch,CURLOPT\u FOLLOWLOCATION,true),但它显示“第32行中的解析错误”第32行是:cURL\u setopt($ch,CURLOPT\u HTTPAUTH,CURLAUTH\u ANY);我需要添加与https相关的内容吗?因为在第二步中,它使用https和端口443。我忘记了
在行尾!curl_error($ch)出现错误:最多(20)次重定向------仍然没有输出。哇!!在添加了curl_setopt($ch,CURLOPT_COOKIEJAR,“/tmp/cookies.txt”)之后,它终于起作用了;curl_setopt($ch,CURLOPT_COOKIEFILE,'/tmp/cookies.txt');curl_setopt($ch,CURLOPT_FOLLOWLOCATION,true);
URL: GET http://www.abcdefg.com/12345/
Status: 200 OK
Protocol: http
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);