我不知道我是否在问一个正确的问题!但我认为它的答案将指导我解决我的问题......
我正在尝试通过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 "\n\n";
echo $testclient->__getLastResponse();
echo "\n\n";
echo $testclient->__getLastResponseHeaders();
echo "\n\n";
} 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”
如果您对我的问题有任何解决方案,请告诉我们!还有我的问题的答案!
非常感谢您的帮助和时间;)
--------------------------------------------
更新
好的,现在我知道它正在发送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
我还在努力,但我会感激任何帮助或劝告!
答案 0 :(得分:1)
客户端HTTP POST是调用目录而不是脚本吗?我的意思是说/ PATH_TO_API可能是服务器上的目录,而你的脚本是该目录中的index.php。在这种情况下,您需要在POST命令后附加一个尾部斜杠,以便Web服务器返回默认文档。 当您收到405错误时,服务器日志会说什么?此外,您可以将参数作为GET而不是POST发送。