http_code 0 是 Redhat php curl 返回的错误代码。

3
我可以使用lynx从服务器访问网站没有问题。但是当我尝试使用php curl指令访问同一个网站时,从curl_getinfo($ch)得到的http_code是0。
在同一个数据中心的另一台红帽服务器上,相同的php代码可以正常工作。我对服务器有管理员权限。
我尝试过php 7.4和php 8.0。 当我调用phpinfo()时,curl是启用的。 我不确定如何调试这个错误!
这是curl_getinfo($ch)的输出。
数组([url] => https://.... [content_type] => [http_code] => 0 [header_size] => 0 [request_size] => 0 [filetime] => -1 [ssl_verify_result] => 0 [redirect_count] => 0 [total_time] => 0.055895 [namelookup_time] => 0.105978 [connect_time] => 0 [pretransfer_time] => 0 [size_upload] => 0 [size_download] => 0 [speed_download] => 0 [speed_upload] => 0 [download_content_length] => -1 [upload_content_length] => -1 [starttransfer_time] => 0 [redirect_time] => 0 [redirect_url] => [primary_ip] => [certinfo] => Array() [primary_port] => 0 [local_ip] => [local_port] => 0 [http_version] => 0 [protocol] => 0 [ssl_verifyresult] => 0 [scheme] => [appconnect_time_us] => 0 [connect_time_us] => 0 [namelookup_time_us] => 105978 [pretransfer_time_us] => 0 [redirect_time_us] => 0 [starttransfer_time_us] => 0 [total_time_us] => 55895)

1
设置 CURLOPT_VERBOSE = true,然后比较服务器之间的信息。 - undefined
2个回答

2

0
我可以使用Lynx来访问一个网站。
可能你无法通过curl命令行访问它,因为涉及到了cookies。
# err
$ curl https:// --verbose
# suc
$ curl https:// \
      --verbose \
      --cookie="/tmp/cookie.txt" \
      --cookie-jar="/tmp/cookie.txt"

PHP表示

$cookieFile = '/tmp/cookie.txt';
$ch = curl_init($url);
curl_setopt_array($ch, [
   CURLOPT_COOKIEJAR => $cookieFile,
   CURLOPT_COOKIEFILE => $cookieFile,
   // other options
]);
curl_exec($ch);
curl_close($ch);


没有变化。我将cookie设置为cookie.txt而不是/tmp/cookie.txt,但是我得到了相同的错误和没有响应。 - undefined

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接