PHP CURL Error - curl: (56) Recv failure: Connection reset by peer

匿名 (未验证) 提交于 2019-12-03 00:52:01

问题:

basically, this error only occurs in CURL

curl: (56) Recv failure: Connection reset by peer 

But when I visit it directly the link directly on my browser, it works!

What are your recommendations on fixing this one or the cause of this error?

Note: the server is coded in ASP and it only occurs on one API Call

回答1:

I remember facing this issue a long time back. While I don't remember what exactly sorted the issue, but I remember trying the following:

1) I was trying to pass the query parameters in the url directly and I tried passing through POST method

2) I tried using a proxy with curl to see if I was possibly being blocked by the other server

3) I believe I also asked my host to look into it and they made some Apache setting changes



回答2:

I resolved this issue by removing whitespace characters from the URL. In my situation, it was the proxy server that was erroring out, not the web server.

In PHP:

     curl_setopt($ch, CURLOPT_URL, trim($url)); 


回答3:

I had similar problem with this code:

        $url = "http://xxx.xxx.xxx.xxx";         $ch = curl_init();         curl_setopt($ch, CURLOPT_PORT, 44455); //Set the port to connect to         //curl_setopt($ch, CURLOPT_RETURNTRANSFER, 44455);          curl_setopt($ch, CURLOPT_URL, $url);         echo $xml = curl_exec($ch);         if(curl_errno($ch))         {             echo 'error:' . curl_error($ch);         }         curl_close($ch); 

Got it solved by disabling this:

        //curl_setopt($ch, CURLOPT_RETURNTRANSFER, 44455); 


标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!