21,886
社区成员
发帖
与我相关
我的任务
分享
<?php
ini_set("display_errors", "On"); error_reporting(E_ALL);
header('Content-Type:text/html;charset= utf-8'); //发送头部信息,确认页面编码
$user = 'aaa';
$pass = 'a';
$curlPost="username=" . $user . '&pwd=' . $pass . '&submit=send'; //定义需要发送的字符串,关键字与它的值
$ch=curl_init(); //初始化一个curl
curl_setopt($ch,CURLOPT_URL,'http://example.com/myservice/service.asmx?WSDL&op=UserLogin'); //设置目标URL
curl_setopt($ch,CURLOPT_POST,1); //设置使用POST发送数据
curl_setopt($ch,CURLOPT_POSTFIELDS,$curlPost); //设置POST数据内容为前面定义的字符串
curl_setopt($ch,CURLOPT_RETURNTRANSFER,1); //设置是否输出返回结果(设置为不打印)
$data=curl_exec($ch); //执行请求并返回结果
curl_close($ch); //关闭CURL
echo $data; //输出结果
?>
<?xml version="1.0" encoding="utf-8" ?>
- <soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
- <soap:Body>
- <soap:Fault>
- <soap:Code>
<soap:Value>soap:Receiver</soap:Value>
</soap:Code>
- <soap:Reason>
<soap:Text xml:lang="en">Server was unable to process request. ---> Data at the root level is invalid. Line 1, position 1.</soap:Text>
</soap:Reason>
<soap:Detail />
</soap:Fault>
</soap:Body>
</soap:Envelope>
<?php
$requstxml=$xml = <<<EOT
<?xml version="1.0" encoding="utf-8"?>
<soap12:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://www.w3.org/2003/05/soap-envelope">
<soap12:Body>
<UserLogin xmlns="http://tempuri.org/">
<username>test</username>
<pwd>test</pwd>
</UserLogin>
</soap12:Body>
</soap12:Envelope>
EOT;
$ch=curl_init('http://218.57.143.249/svctest/service.asmx');
curl_setopt($ch,CURLOPT_POST,true);
curl_setopt($ch,CURLOPT_POSTFIELDS,$requstxml);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-Type: application/soap+xml; charset=utf-8", "Content-length: ".strlen($requstxml)));
$data=curl_exec($ch);
curl_close($ch);
echo $data;
?>
ini_set("display_errors", "On"); error_reporting(E_ALL);
header('Content-Type:text/html;charset= utf-8'); //发送头部信息,确认页面编码
$user = 'aaa';
$pass = 'a';
$curlPost = <<<post
<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:tem="http://tempuri.org/">
<soap:Header/>
<soap:Body>
<tem:UserLogin>
<!--Optional:-->
<tem:username>{$user}</tem:username>
<!--Optional:-->
<tem:pwd>{$pass}</tem:pwd>
</tem:UserLogin>
</soap:Body>
</soap:Envelope>
post;
$ch=curl_init('http://218.57.143.249/svctest/service.asmx'); //初始化一个curl
//curl_setopt($ch,CURLOPT_URL,''); //设置目标URL
curl_setopt($ch,CURLOPT_POST,true); //设置使用POST发送数据
curl_setopt($ch,CURLOPT_POSTFIELDS,$curlPost); //设置POST数据内容为前面定义的字符串
curl_setopt($ch,CURLOPT_RETURNTRANSFER,true); //设置是否输出返回结果(设置为不打印)
curl_setopt($ch,CURLOPT_HTTPHEADER,array('Content-Type: application/soap+xml;charset=UTF-8;action="http://tempuri.org/UserLogin"'));
$data=curl_exec($ch); //执行请求并返回结果
curl_close($ch); //关闭CURL
echo $data; //输出结果
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, Your Webserviceurl);
curl_setopt($ch, CURLOPT_PORT , 443);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_TIMEOUT, 20);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $requestxml);
curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-Type: application/soap+xml; charset=utf-8", "Content-length: ".strlen($requestxml)));
$response = curl_exec($ch);
$statuscode = curl_getinfo($ch,CURLINFO_HTTP_CODE);
curl_close($ch);
switch($statuscode) {
判断状态码
}
$requestxml="<?xml version=\"1.0\" encoding=\"utf-8\"?>".
"<soap12:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:soap12=\"http://www.w3.org/2003/05/soap-envelope\"> ""
等等,以下就不写了
POST http://example.com/myservice/service.asmx HTTP/1.1
Connection: close
Accept-Encoding: gzip,deflate
Content-Type: application/soap+xml;charset=UTF-8;action="http://tempuri.org/UserLogin"
User-Agent: Jakarta Commons-HttpClient/3.1
Host: example.com
Content-Length: 343
<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:tem="http://tempuri.org/">
<soap:Header/>
<soap:Body>
<tem:UserLogin>
<!--Optional:-->
<tem:username>?</tem:username>
<!--Optional:-->
<tem:pwd>?</tem:pwd>
</tem:UserLogin>
</soap:Body>
</soap:Envelope>
<?xml version="1.0" encoding="utf-8" ?>
- <wsdl:definitions xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:tm="http://microsoft.com/wsdl/mime/textMatching/" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:mime="http://schemas.xmlsoap.org/wsdl/mime/" xmlns:tns="http://tempuri.org/" xmlns:s="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/" xmlns:http="http://schemas.xmlsoap.org/wsdl/http/" targetNamespace="http://tempuri.org/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/">
- <wsdl:types>
- <s:schema elementFormDefault="qualified" targetNamespace="http://tempuri.org/">
- <s:element name="UserLogin">
- <s:complexType>
- <s:sequence>
<s:element minOccurs="0" maxOccurs="1" name="username" type="s:string" />
<s:element minOccurs="0" maxOccurs="1" name="pwd" type="s:string" />
</s:sequence>
</s:complexType>
</s:element>
- <s:element name="UserLoginResponse">
- <s:complexType>
- <s:sequence>
<s:element minOccurs="0" maxOccurs="1" name="UserLoginResult" type="s:string" />
</s:sequence>
</s:complexType>
</s:element>
</s:schema>
</wsdl:types>
- <wsdl:message name="UserLoginSoapIn">
<wsdl:part name="parameters" element="tns:UserLogin" />
</wsdl:message>
- <wsdl:message name="UserLoginSoapOut">
<wsdl:part name="parameters" element="tns:UserLoginResponse" />
</wsdl:message>
- <wsdl:portType name="Service1Soap">
- <wsdl:operation name="UserLogin">
<wsdl:input message="tns:UserLoginSoapIn" />
<wsdl:output message="tns:UserLoginSoapOut" />
</wsdl:operation>
</wsdl:portType>
- <wsdl:binding name="Service1Soap" type="tns:Service1Soap">
<soap:binding transport="http://schemas.xmlsoap.org/soap/http" />
- <wsdl:operation name="UserLogin">
<soap:operation soapAction="http://tempuri.org/UserLogin" style="document" />
- <wsdl:input>
<soap:body use="literal" />
</wsdl:input>
- <wsdl:output>
<soap:body use="literal" />
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
- <wsdl:binding name="Service1Soap12" type="tns:Service1Soap">
<soap12:binding transport="http://schemas.xmlsoap.org/soap/http" />
- <wsdl:operation name="UserLogin">
<soap12:operation soapAction="http://tempuri.org/UserLogin" style="document" />
- <wsdl:input>
<soap12:body use="literal" />
</wsdl:input>
- <wsdl:output>
<soap12:body use="literal" />
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
- <wsdl:service name="Service1">
- <wsdl:port name="Service1Soap" binding="tns:Service1Soap">
<soap:address location="http://example.com/myservice/service.asmx" />
</wsdl:port>
- <wsdl:port name="Service1Soap12" binding="tns:Service1Soap12">
<soap12:address location="http://example.com/myservice/service.asmx" />
</wsdl:port>
</wsdl:service>
</wsdl:definitions>