我不知道我问的问题是否正确!但我认为它的答案将指导我解决我的问题。
我试图通过SoapClient调用一个函数,…这是我的代码的简化版本:
class SOAP_AuthStruct {
function __construct($user, $pass) {
$this->Username = strval($user);
$this->Password = strval($pass);
}
}
$soap_loc = "SET TO SOAP PATH";
$soap_opts = array (
'location' => $soap_loc,
'style' => SOAP_DOCUMENT,
'use' => SOAP_LITERAL,
'cache_wsdl' => WSDL_CACHE_NONE,
'exceptions' => FALSE,
'trace' => TRUE
);
$testclient = new SoapClient("soapcall.wsdl", $soap_opts);
$soap_auth = new SOAP_AuthStruct("USERNAME", "PASSWORD");
$soap_header = new SoapHeader($soap_ns,'AuthHeader',$soap_auth,FALSE);
// $a_param is filled with essential values
$soap_param = array("CreateTransaction" => $a_param);
try {
$result = $testclient->__soapCall("CreateTransaction", $soap_param, NULL, $soap_header, $output_headers);
echo $testclient->__getLastRequest();
echo "nn";
echo $testclient->__getLastResponse();
echo "nn";
echo $testclient->__getLastResponseHeaders();
echo "nn";
} catch (SoapFault $fault) {
trigger_error("SOAP Fault: (faultcode: {$fault->faultcode}, faultstring: {$fault->faultstring})", E_USER_ERROR);
}
我有一个正确请求格式的示例,getLastRequest()函数显示请求具有正确的格式…
但是在响应中我有这个错误消息:
HTTP/1.1 405 Method Not Allowed
X-Mashery-Responder: XXXXX.mashery.com
Allow: GET, HEAD, OPTIONS, TRACE
Content-Type: text/html
Server: Microsoft-IIS/7.5
X-Powered-By: ASP.NET
Date: Tue, 12 Apr 2011 18:34:29 GMT
Accept-Ranges: bytes
Content-Length: 1293
我认为(我不确定!)可能是SoapClient使用POST方法发送请求,我在响应头中找不到它:"允许:GET, HEAD, OPTIONS, TRACE"
请让我知道如果你有任何解决我的问题!也是我问题的答案!
提前感谢您的帮助和您的时间;)
--------------------------------------------
更新:
OK,现在我知道它正在发送POST请求!
我将这行添加到我的代码中(在调用函数之后)
echo $testclient->__getLastRequestHeaders();
返回:
POST /RimWebAPI/?api_key=APIKEY&sig=SIGNATURE HTTP/1.1
Host: something.com
Connection: Keep-Alive
User-Agent: PHP-SOAP/5.1.6
Content-Type: text/xml; charset=utf-8
SOAPAction: "SOAP ACTION"
Content-Length: 2344
我还在做,但我会感谢任何帮助或指导!
客户端HTTP POST调用目录而不是脚本吗?我的意思是说,有可能/PATH_TO_API是服务器上的一个目录,而您的脚本是该目录下的index.php。在这种情况下,你需要在POST命令后面加上一个斜杠,这样web-server就会返回默认文档。当您得到405错误时,服务器日志显示什么?此外,您可以将参数作为GET而不是POST发送吗?