Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/271.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/windows/17.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
在Windows上发出PHP cURL请求会产生“收益”;“400错误请求”;从代理_Php_Windows_Http_Curl_Proxy - Fatal编程技术网

在Windows上发出PHP cURL请求会产生“收益”;“400错误请求”;从代理

在Windows上发出PHP cURL请求会产生“收益”;“400错误请求”;从代理,php,windows,http,curl,proxy,Php,Windows,Http,Curl,Proxy,早上好 基本上,由于涉及代理服务器的问题,我无法从Windows 7开发PC向内部和外部服务器发出成功的cURL请求。我正在Apache2.4上运行curl7.21.2到PHP5.3.6 以下是失败的最基本请求: <?php $curl = curl_init('http://www.google.com'); $log_file = fopen(sys_get_temp_dir() . 'curl.log', 'w'); curl_setopt_array($curl, array

早上好

基本上,由于涉及代理服务器的问题,我无法从Windows 7开发PC向内部和外部服务器发出成功的cURL请求。我正在Apache2.4上运行curl7.21.2到PHP5.3.6

以下是失败的最基本请求:

<?php

$curl = curl_init('http://www.google.com');

$log_file = fopen(sys_get_temp_dir() . 'curl.log', 'w');

curl_setopt_array($curl, array(
    CURLOPT_RETURNTRANSFER => TRUE,
    CURLOPT_VERBOSE => TRUE,
    CURLOPT_HEADER => TRUE,
    CURLOPT_STDERR => $log_file,
));

$response = curl_exec($curl);

@fclose($log_file);

print "<pre>{$response}";
cURL生成的日志文件包含以下内容

<?php

$curl = curl_init('http://www.google.com');

$log_file = fopen(sys_get_temp_dir() . 'curl.log', 'w');

curl_setopt_array($curl, array(
    CURLOPT_RETURNTRANSFER => TRUE,
    CURLOPT_VERBOSE => TRUE,
    CURLOPT_HEADER => TRUE,
    CURLOPT_STDERR => $log_file,
    CURLOPT_PROXY => 'http://usushproxy01.unistudios.com:7070',
    CURLOPT_PROXYUSERPWD => '<username>:<password>',
));

$response = curl_exec($curl);

@fclose($log_file);

print "<pre>{$response}";
*即将()连接到代理ususushproxy01.unistudios.com端口7070(#0)
*正在尝试216.178.96.20…*有联系的
*连接到usushsproxy01.unistudios.com(216.178.96.20)端口7070(#0)
>得到http://www.google.com HTTP/1.1
主持人:www.google.com
接受:*/*
代理连接:保持活动状态
明确声明代理和用户凭据(如下所示)没有任何区别:响应总是相同的


您可能正在查看cURL(Windows和Linux之间的不同版本)和IronPort版本之间的问题。在IronPort文档中:

修复:Web代理使用代理连接头而不是 连接头,导致某些用户代理出现问题

以前,Web代理使用代理连接头而不是 使用显式连接与用户代理通信时的连接头 转发请求。因此,一些用户代理,例如Real 玩家,未按预期工作。这种情况不再发生。现在,网络 代理使用连接头和 代理连接头。[缺陷ID:46515]

尝试删除
代理连接
(或添加
连接
)标题,看看这是否解决了问题


此外,您可能希望比较Windows和Linux主机之间的cURL日志。

您可能会发现cURL(Windows和Linux之间的不同版本)和IronPort版本之间存在问题。在IronPort文档中:

修复:Web代理使用代理连接头而不是 连接头,导致某些用户代理出现问题

以前,Web代理使用代理连接头而不是 使用显式连接与用户代理通信时的连接头 转发请求。因此,一些用户代理,例如Real 玩家,未按预期工作。这种情况不再发生。现在,网络 代理使用连接头和 代理连接头。[缺陷ID:46515]

尝试删除
代理连接
(或添加
连接
)标题,看看这是否解决了问题


此外,您可能希望比较Windows和Linux主机之间的cURL日志。

您是否尝试过设置
CURLOPT\u HTTPPROXYTUNNEL
?谢谢,@goldenparrot。我试过了,但没有改善情况。你应该添加一个UserAgent头。可能会改善谷歌的感知。你试过设置
CURLOPT\u HTTPPROXYTUNNEL
?谢谢,@goldenparrot。我试过了,但没有改善情况。你应该添加一个UserAgent头。可能会改善谷歌的认知。谢谢你的帮助,@lserni。这看起来确实很有希望,但不幸的是,这对我的电话没有任何影响。我试了两种组合。再次感谢你,tho。谢谢你的帮助,@lserni。这看起来确实很有希望,但不幸的是,这对我的电话没有任何影响。我试了两种组合。再次感谢你,tho。
* About to connect() to proxy usushproxy01.unistudios.com port 7070 (#0)
*   Trying 216.178.96.20... * connected
* Connected to usushproxy01.unistudios.com (216.178.96.20) port 7070 (#0)
> GET http://www.google.com HTTP/1.1
Host: www.google.com
Accept: */*
Proxy-Connection: Keep-Alive

< HTTP/1.1 400 Bad Request
< Date: Thu, 06 Sep 2012 17:12:58 GMT
< Content-Length: 171
< Content-Type: text/html
< Server: IronPort httpd/1.1
< 
* Connection #0 to host usushproxy01.unistudios.com left intact
<?php

$curl = curl_init('http://www.google.com');

$log_file = fopen(sys_get_temp_dir() . 'curl.log', 'w');

curl_setopt_array($curl, array(
    CURLOPT_RETURNTRANSFER => TRUE,
    CURLOPT_VERBOSE => TRUE,
    CURLOPT_HEADER => TRUE,
    CURLOPT_STDERR => $log_file,
    CURLOPT_PROXY => 'http://usushproxy01.unistudios.com:7070',
    CURLOPT_PROXYUSERPWD => '<username>:<password>',
));

$response = curl_exec($curl);

@fclose($log_file);

print "<pre>{$response}";