duanhuau567787
2014-09-30 17:09
浏览 31
已采纳

替代fsockopen与卷曲在PHP中

I am trying to call a web service of a shipping company in my php code and get the result xml. I have this sample code and i want to know if there is an alternative using curl.

Code:

  function doPost($_postContent) {
    $postContent = "xml_in=".$_postContent;

    $host="test.company.com";
    $contentLen = strlen($postContent);

    $httpHeader ="POST /shippergate2.asp HTTP/1.1
"
        ."Host: $host
"
        ."User-Agent: PHP Script
"
        ."Content-Type: application/x-www-form-urlencoded
"
        ."Content-Length: $contentLen
"
        ."Connection: close
"
        ."
";

    $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("

", $result,3);
}

Can i call it using curl?

图片转代码服务由CSDN问答提供 功能建议

我正在尝试在我的php代码中调用运输公司的Web服务并获取结果xml。 我有这个示例代码,我想知道是否有使用curl的替代方法。</ p>

代码:</ p>

  function doPost($ _ postContent  ){
 $ postContent =“xml_in =”。$ _ postContent; 
 
 $ host =“test.company.com”; 
 $ contentLen = strlen($ postContent); 
 
 $ httpHeader =“POST  /shippergate2.asp HTTP / 1.1 
 
“
。”主机:$ host 
 
“
。”用户代理:PHP脚本
 
“
。”内容类型:application /  x-www-form-urlencoded 
 
“
。”内容长度:$ contentLen 
 
“
。”连接:关闭
 
“
。”
 
“;”\  n 
 $ httpHeader。= $ postContent; 
 
 
 $ fp = fsockopen($ host,81); 
 
 fputs($ fp,$ httpHeader); 
 
 $ result =“”;  
 
 while(!feof($ fp)){
 //收到请求的结果
 $ result。= fgets($ fp,128); 
} 
 
 //关闭套接字 连接:
 
 fclose($ fp); 
 
 $ result = explode(“
 
 
 
”,$ result,3); 
} 
 </ code> </ pre  > 
 
 

我可以用cur调用它 l?</ p> </ div>

2条回答 默认 最新

相关推荐 更多相似问题