如何使用PHP发送和接收xml(SOAP Web服务)



我想连接到h1tps://ediwebs.sweatheranalysis.com.tr/sweatheranalysisediwebs.asmx?op=GetAnalysis并使用SoapClient或其他任何请求发送

POST /sweatheranalysisediwebs.asmx HTTP/1.1
Host: ediwebs.sweatheranalysis.com.tr
Content-Type: application/soap+xml; charset=utf-8
Content-Length: length
<?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:Header>
<AuthHeader xmlns="http://sweatheranalysis.com.tr/ediwebs/">
<Partner>string</Partner>
<Password>string</Password>
</AuthHeader>
</soap12:Header>
<soap12:Body>
<GetAnalysis xmlns="http://sweatheranalysis.com.tr/ediwebs/" />
</soap12:Body>
</soap12:Envelope>

响应类似于以下内容:

HTTP/1.1 200 OK
Content-Type: application/soap+xml; charset=utf-8
Content-Length: length
<?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:Header>
<AuthHeader xmlns="http://sweatheranalysis.com.tr/ediwebs/">
<Partner>string</Partner>
<Password>string</Password>
</AuthHeader>
</soap12:Header>
<soap12:Body>
<GetAnalysisResponse xmlns="http://sweatheranalysis.com.tr/ediwebs/">
<GetAnalysisResult>xml</GetAnalysisResult>
</GetAnalysisResponse>
</soap12:Body>
</soap12:Envelope>

我该怎么做? 我试过这个,但我收到错误无效登录。 使用SOAPUI一切正常

try{
$username = 'username';
$password = 'password';
$soapURL = "https://ediwebs.sweatheranalysis.com.tr/sweatheranalysisediwebs.asmx?WSDL";
$client = new SoapClient($soapURL, [
'stream_context' => stream_context_create([
'ssl' => [
'verify_peer' => false,
'verify_peer_name' => false,
]
])
]);
$auth = array(
'Partner' => $username,
'Password' => $password,
);
$header = new SoapHeader('http://sweatheranalysis.com.tr/ediwebs/','AuthHeader',$auth,'false');
$client->__setSoapHeaders($header);
$response = $client->__soapCall("GetAnalysis",$auth);
var_dump($response);
}catch(Exception $e){
echo $e->getMessage();
}

$header = new SoapHeader('http://sweatheranalysis.com.tr/ediwebs/', 'AuthHeader',$auth,'false');更改了此行$header = new SoapHeader('http://sweatheranalysis.com.tr/ediwebs/', 'AuthHeader',array('Partner' => 'username', 'Password' => 'password'),'false');和工作

最新更新