系统升级后,发现有个远程ucenter应用测试老是通信失败,于是一步步调试查找原因,最后发现是因为ucenter中的一个函数dfopen有BUG,他老会自动带上80端口,而有些服务器碰上80端口的请求会自动302重定向到不带端口域名下,即从www.324324.cn:80重定向到www.324324.cn,这时远程调用请求就会返回302响应,造成通信失败。- GET /api/uc.php?code=0690yeurtGqQZ0lp62...... HTTP/1.0
- Accept: */*
- Accept-Language: zh-cn
- User-Agent: Mozilla/5.0 (Windows NT 6.2; WOW64) AppleWebKit/537.17 (KHTML, like Gecko) Chrome/24.0.1312.57 Safari/537.17
- Host: www.324324.cn:80
- Connection: Close
- Cookie:
复制代码 return data:- 302 Found
- [align=center][size=1]302 Found[/size]
- [/align]
- [align=center]nginx[/align]
复制代码 uc_server/model/msic.php第62到93行,可以看到,默认都加了80端口。- function dfopen($url, $limit = 0, $post = '', $cookie = '', $bysocket = FALSE , $ip = '', $timeout = 15, $block = TRUE, $encodetype = 'URLENCODE') {
- //error_log("[uc_server]rnurl: $urlrnpost: $postrnrn", 3, 'c:/log/php_fopen.txt');
- $return = '';
- $matches = parse_url($url);
- $host = $matches['host'];
- $path = $matches['path'] ? $matches['path'].($matches['query'] ? '?'.$matches['query'] : '') : '/';
- $port = !empty($matches['port']) ? $matches['port'] : 80;
- if($post) {
- $out = "POST $path HTTP/1.0rn";
- $out .= "Accept: */*rn";
- //$out .= "Referer: $boardurlrn";
- $out .= "Accept-Language: zh-cnrn";
- $boundary = $encodetype == 'URLENCODE' ? '' : ';'.substr($post, 0, trim(strpos($post, "n")));
- $out .= $encodetype == 'URLENCODE' ? "Content-Type: application/x-www-form-urlencodedrn" : "Content-Type: multipart/form-data$boundaryrn";
- $out .= "User-Agent: $_SERVER[HTTP_USER_AGENT]rn";
- $out .= "Host: $host:$portrn";
- $out .= 'Content-Length: '.strlen($post)."rn";
- $out .= "Connection: Closern";
- $out .= "Cache-Control: no-cachern";
- $out .= "Cookie: $cookiernrn";
- $out .= $post;
- } else {
- $out = "GET $path HTTP/1.0rn";
- $out .= "Accept: */*rn";
- //$out .= "Referer: $boardurlrn";
- $out .= "Accept-Language: zh-cnrn";
- $out .= "User-Agent: $_SERVER[HTTP_USER_AGENT]rn";
- $out .= "Host: $host:$portrn";
- $out .= "Connection: Closern";
- $out .= "Cookie: $cookiernrn";
- }
复制代码 我把其中第78行和第90行的代码:- $out .= "Host: $host:$portrn";
复制代码 改为如下:- $out .= "Host: $host".($port==80?"":":$port")."rn";
复制代码 就正常了。。。 |