12

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

Jeffrey Monte
  • 680
  • 1
  • 5
  • 12
  • yeah on the console, that is also the error, there is no header/options on the curl request. and also there is no cookie involve.. – Jeffrey Monte Jul 16 '12 at 08:53
  • I am guessing that this is a Server Error, but I do not know what part or section of the Server this occurs – Jeffrey Monte Jul 16 '12 at 08:54
  • are you getting any errors in your webserver log? Is the server running on the same machine, where the curl commando is executed? If so try to add the called domain to map to localhost in your hosts file... – MatthiasLaug Jul 16 '12 at 19:58
  • I solved this by requesting via POST instead of GET – darryn.ten Dec 07 '16 at 15:08

3 Answers3

5

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));
Adam Albright
  • 5,917
  • 1
  • 21
  • 14
  • If the whitespace characters are a valid part of the URL, you could use the rawurlencode() function instead, to replace whitespace characters with %20 – sudoqux Apr 25 '17 at 08:45
4

I remember facing the same issue a long time back. While I don't remember what exactly sorted out the issue, 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

David Refoua
  • 3,476
  • 3
  • 31
  • 55
Sam
  • 532
  • 6
  • 12
  • 2
    Do you remember what the result was? – Hudson Atwell Dec 10 '12 at 23:06
  • I think the host did change some Apache settings but not sure what settings they were. Immediately after changing the settings, it started working. Also there might have been an issue with the way I was sending the parameters in my curl request. – Sam Dec 12 '12 at 11:41
  • I also here that litespeed anti ddos measures might be placing a temp ban on the calling IP. I believe this is what happened to me. We are still in discussion. – Hudson Atwell Dec 13 '12 at 21:42
0

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);
user109764
  • 576
  • 6
  • 11