0
我想在我的PHP代码中调用一家航运公司的Web服务并获得结果xml。我有这个示例代码,我想知道是否有使用卷曲的替代方法。在PHP中使用curl替代fsockopen
代码:
function doPost($_postContent) {
$postContent = "xml_in=".$_postContent;
$host="test.company.com";
$contentLen = strlen($postContent);
$httpHeader ="POST /shippergate2.asp HTTP/1.1\r\n"
."Host: $host\r\n"
."User-Agent: PHP Script\r\n"
."Content-Type: application/x-www-form-urlencoded\r\n"
."Content-Length: $contentLen\r\n"
."Connection: close\r\n"
."\r\n";
$httpHeader.=$postContent;
$fp = fsockopen($host, 81);
fputs($fp, $httpHeader);
$result = "";
while(!feof($fp)) {
// receive the results of the request
$result .= fgets($fp, 128);
}
// close the socket connection:
fclose($fp);
$result = explode("\r\n\r\n", $result,3);
}
我可以调用它使用curl?
日Thnx为回复。 “标准”是什么意思? – 2014-09-30 17:43:14
对不起,这可能是令人困惑的。标准的HTTP 1.1是RFC 2616.你发布的例子是标准的HTTP,并且这将适用于此。 – 2014-09-30 18:24:33
我还需要包括标题:内容类型/长度等...? – 2014-10-01 07:59:14