我想通过 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/