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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/11500847/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 00:40:25  来源:igfitidea点击:

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

phpcurl

提问by Jeffrey Monte

basically, this error only occurs in CURL

基本上,这个错误只发生在 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

注意:服务器是用 ASP 编码的,它只发生在一个 API 调用上

采纳答案by Sam

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

  1. 我试图直接在 URL 中传递查询参数,我尝试通过 POST 方法传递

  2. 我尝试使用带有 curl 的代理来查看我是否可能被其他服务器阻止

  3. 我相信我也要求我的主人调查它,他们对 Apache 设置进行了一些更改

回答by Adam Albright

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

我通过从 URL 中删除空格字符解决了这个问题。在我的情况下,出错的是代理服务器,而不是 Web 服务器。

In PHP:

在 PHP 中:

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

回答by user109764

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);