以下是SOAP 1.1请求和响应示例
POST /DEMOWebServices2.8/service.asmx HTTP/1.1
Host: api.efxnow.com
Content-Type: text/xml; charset=utf-8
Content-Length: length
SOAPAction: "https://api.efxnow.com/webservices2.3/DealRequestAtBest"
<?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>
<Authenticator xmlns="https://api.efxnow.com/webservices2.3">
<ApplicationName>string</ApplicationName>
<IPAddress>string</IPAddress>
<UserID>string</UserID>
<MachineName>string</MachineName>
</Authenticator>
</soap:Header>
<soap:Body>
<DealRequestAtBest xmlns="https://api.efxnow.com/webservices2.3">
<UserID>string</UserID>
<PWD>string</PWD>
<Pair>string</Pair>
</DealRequestAtBest>
</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>
<DealRequestAtBestResponse xmlns="https://api.efxnow.com/webservices2.3">
<DealRequestAtBestResult>
<Success>boolean</Success>
<ErrorDescription>string</ErrorDescription>
<ErrorNumber>int</ErrorNumber>
<Confirmation>string</Confirmation>
<ConfirmationNumber>string</ConfirmationNumber>
<Rate>double</Rate>
</DealRequestAtBestResult>
</DealRequestAtBestResponse>
</soap:Body>
</soap:Envelope>
如果必须在php中完成,我想知道如何发出请求以及如何处理响应。我看了this,但我无法弄清楚如何在我的案例中实施__setSoapHeaders()
和__call()
。提前谢谢。
答案 0 :(得分:1)
有一个用于PHP的SOAP库,但是对于简单的交换,您可以考虑将XML请求体构建为字符串并使用curl库函数对其进行分派。这是一个更低级别的网络API,我至少觉得它更容易使用。请注意,PHP需要编译--with-curl [= DIR]。
<?php
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $uri);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
if ((bool)$proxy) {
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Pragma:','Cache-Control:'));
curl_setopt($ch, CURLOPT_PROXY, $proxy);
}
// Apply the XML to our curl call
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $xml_data);
$out = curl_exec($ch);
curl_close($ch);
?>