failed to open stream: HTTP request failed! HTTP/1.1 505 HTTP Version Not Supported

PHP模拟GET请求支付宝退款链接(未用sdk  自己拼接的请求链接与参数);

起初用file_get_contents();就报错 :failed to open stream: HTTP request failed! HTTP/1.1 505 HTTP Version Not Supported!!!

换成 curl模拟get 请求 返回值为空 没错 直接没报错 返回空字符串,,,以为curl参数设置不对,各种试到怀疑人生

接着继续 获取  $info = curl_getinfo($ch); 查看信息

发现 http_code 为 505 ,查到说是 不支持 HTTP/1.1的有(此处肯定不是该原因) 也有说请求格式不对 要 去除空格

直接 对URL   preg_replace('# #','',$url) 再请求

接着  支付宝 又返回时间参数格式有错  也就是 yyy-MM-dd HH:mm:ss 中间的空格还不能没有  

看到一篇文章  解决了该问题 : https://blog.csdn.net/bianb123/article/details/81557300

preg_replace('# #','%20',$url);

再回头  无论 file_get_contents(); 还是curl 都可成功请求, 期待已久的  

"code":"10000","msg":"Success"

终于出来了

特此记录!

猜你喜欢

转载自www.cnblogs.com/yimingwang/p/11367245.html