php curl post请求soap webservice接口

 

直接上代码了。

SOAP 1.1

The following is a sample SOAP 1.1 request and response. The placeholders shown need to be replaced with actual values.

POST /AirLogisticsAPP/AirLogisticsService.asmx HTTP/1.1
Host: 58.213.128.130
Content-Type: text/xml; charset=utf-8
Content-Length: length
SOAPAction: "http://58.213.128.130/HelloWorld"

<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
  <soap:Body>
    <HelloWorld xmlns="http://58.213.128.130/" />
  </soap:Body>
</soap:Envelope>
HTTP/1.1 200 OK
Content-Type: text/xml; charset=utf-8
Content-Length: length

<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
  <soap:Body>
    <HelloWorldResponse xmlns="http://58.213.128.130/">
      <HelloWorldResult>string</HelloWorldResult>
    </HelloWorldResponse>
  </soap:Body>
</soap:Envelope>
    /**
     * 使用curl发送post请求
     * @param $url
     * @param string $data
     * @return bool|mixed
     */
    public function sendCurlPost($url, $header = '', $post){
        //初始化,创建一个cURL资源
        $ch = curl_init();
        //设置cURL选项
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_USERAGENT, "user-agent:Mozilla/5.0 (Windows NT 5.1; rv:24.0) Gecko/20100101 Firefox/24.0");
        curl_setopt($ch, CURLOPT_HEADER, 0);    //是否返回文件头信息
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);    //不直接打印输出
        curl_setopt($ch, CURLOPT_POST, 1);  //是否post请求
        curl_setopt($ch, CURLOPT_POSTFIELDS, $post); //post传输数据
        curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
        //执行cURL会话
        $response = curl_exec($ch);
        file_put_contents("log11ss.txt", $response);

        if (!curl_errno($ch)){
            $result =  $response;
        }else{
        //    echo 'Curl error: ' . curl_error($ch);
            $result = false;
        }
     
        //关闭cURL释放资源
        curl_close($ch);
     
        return $result;
    }
     
    public function ceshiweb()
    {
        $url = "http://58.213.128.130:888/AirLogisticsAPP/AirLogisticsService.asmx";
        $header[] = "Content-type: text/xml";

        $post = "<?xml version='1.0' encoding='utf-8'?>
                <soap:Envelope xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:soap='http://schemas.xmlsoap.org/soap/envelope/'>
                  <soap:Header>
                    <AuthHeaderNKG xmlns='http://58.213.128.130/'>
                      <IATACode>xxx</IATACode>
                      <LoginID>xxx</LoginID>
                      <Password>xxxxxx</Password>
                    </AuthHeaderNKG>
                  </soap:Header>
                  <soap:Body>
                    <CGOGetAWBInformation xmlns='http://58.213.128.130/'>
                      <AWBNumber>618609556xx</AWBNumber>
                      <AWBType>IO</AWBType>
                    </CGOGetAWBInformation>
                  </soap:Body>
                </soap:Envelope>";

        $res = $this->sendCurlPost($url,$header,$post);
        print_r($res);die;
    }

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值