我正在尝试为 Flickr SOAP API 创建请求,但无法获得正确的格式。这是他们想要发送的 XML。:
<s:Envelope
xmlns:s="http://www.w3.org/2003/05/soap-envelope"
xmlns:xsi="http://www.w3.org/1999/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/1999/XMLSchema"
>
<s:Body>
<x:FlickrRequest xmlns:x="urn:flickr">
<method>flickr.test.echo</method>
<name>value</name>
</x:FlickrRequest>
</s:Body>
</s:Envelope>
这是我的代码:
<?php
ini_set("soap.wsdl_cache_enabled", "0"); // disabling WSDL cache
$opts = array('location' => 'http://api.flickr.com/services/soap/',
'uri' => 'urn:flickr',
'trace' => 1
);
$client = new SOAPClient(null, $opts);
?>
<?php
try {
$data = $client->__soapCall('flickr.test.echo', array('name'));
print_r($data);
} catch (SoapFault $exception) {
echo 'Exception Thrown: '.$exception->faultstring.'<br><br>';
print "<pre>\n";
print "Request :\n".htmlspecialchars($client->__getLastRequest()) ."\n";
print "Response:\n".htmlspecialchars($client->__getLastResponse())."\n";
print "</pre>";
}
?>
这是回应:
Exception Thrown:
Request :
<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:ns1="urn:flickr" xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/"
SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<SOAP-ENV:Body>
<ns1:flickr.test.echo>
<param0 xsi:type="xsd:string">name</param0>
</ns1:flickr.test.echo>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
Response:
<?xml version="1.0" encoding="utf-8" ?>
<s:Envelope xmlns:s="http://www.w3.org/2003/05/soap-envelope">
<s:Body>
<s:Fault>
<faultcode>flickr.error.0</faultcode>
<faultstring>Invalid SOAP envelope.</faultstring>
<faultactor>http://www.flickr.com/services/soap/</faultactor>
<details>Please see http://www.flickr.com/services/api/ for more details</details>
</s:Fault>
</s:Body>
</s:Envelope>
不幸的是,Flickr 不提供 WSDL 文件。
谢谢
<< ** 更新 ** >> 我越来越近了。我改变了我的代码,它几乎到了它应该在的地方:
<?php
ini_set("soap.wsdl_cache_enabled", "0"); // disabling WSDL cache
$opts = array('location' => 'http://api.flickr.com/services/soap/',
'uri' => 'http://api.flickr.com/services/soap/',
'trace' => 1
);
$client = new SOAPClient(null, $opts);
?>
<?php
try {
$data = $client->__soapCall("FlickrRequest",
array(new SoapParam('flickr.test.echo', 'method'), new SoapParam('value', 'name')),
array('soapaction' => 'http://api.flickr.com/services/soap/')
);
print_r($data);
} catch (SoapFault $exception) {
echo 'Exception Thrown: '.$exception->faultstring.'<br><br>';
print "<pre>\n";
print "Request :\n".htmlspecialchars($client->__getLastRequest()) ."\n";
print "Response:\n".htmlspecialchars($client->__getLastResponse())."\n";
print "</pre>";
}
?>
现在发送的是:
<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://api.flickr.com/services/soap/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/"
SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<SOAP-ENV:Body>
<ns1:FlickrRequest>
<method xsi:type="xsd:string">flickr.test.echo</method>
<name xsi:type="xsd:string">value</name>
</ns1:FlickrRequest>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>