php - 接收失败 : Connection was reset in Curl PHP

标签 php apache http curl

我想通过 XML 使用 http post 从这个 IP 地址 12.96.12.174 获取一些数据。我为此创建了 curl PHP 代码

 <?php
$url = "http://12.96.12.174";
$post_string = '<?xml version="1.0"?>
<CRMAcresMessage>
<Header ImmediateResponseRequired="true" OriginalBodyRequested="true">
<MessageID>25</MessageID>
<TimeStamp>2016-03-11T011:35:11</TimeStamp>
<Operation Operand="Request" Data="PlayerProfile" />
</Header>
<PlayerID>59979</PlayerID>
<Body>   
</Body>
</CRMAcresMessage>';
$header  = "POST HTTP/1.0 \r\n";
$header .= "Content-type: text/xml \r\n";
$header .= "Content-length: ".strlen($post_string)." \r\n";
$header .= "Content-transfer-encoding: text \r\n";
$header .= "Connection: close \r\n\r\n"; 
$header .= $post_string;
$ch = curl_init();
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_URL,$url);
//$fp = fopen('rss.xml', 'w');
curl_setopt($ch,CURLOPT_PORT, 8085);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 0);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST,  $header);
echo $data = curl_exec($ch);
if(curl_errno($ch))
print curl_error($ch);
else
curl_close($ch);
?>

当我点击来自“http://example.com/members/check.php”的链接时,这个 url 这给了我Recv failure: Connection was reset in Curl

从我的本地主机我得到连接失败

php版本也是>5.3

我是 Curl 的初学者。

最佳答案

curl_setopt($ch, CURLOPT_URL, trim($url));
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);

对于 Recv 失败:Curl PHP 中的连接已重置 ==> 像这样声明:

CURLOPT_SSL_VERIFYPEER as 0 

& 确保您使用的是 PHP 版本 >5.3

关于php - 接收失败 : Connection was reset in Curl PHP,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36575031/

相关文章:

php - php session ID的唯一性

php - 从 Controller 和应用程序文件夹调用 CakePHP 函数

php - Sed 正则表达式通过网络浏览器工作不同

django - 如何在 django 应用程序中流式传输视频

apache - 限制对特定 URL 的访问 (Apache Tomcat)

php - 根据条件(desc 或 asc)在 MySQL 查询后添加逗号

php - SQL 复杂连接

rest - Elasticsearch-无法识别网址中的指定参数

http - Tomcat 服务器,更改默认 HTTP 404?

http - 如何在 LinkedIn OAuth 2.0 身份验证中获取访问 token 应该作为 POST 请求进行?