Answer the question
In order to leave comments, you need to log in
What should I do if, when calling a SOAP method, the request does not pass authorization, although there is access to the WSDL?
Good afternoon!
Php SOAP client does not pass authorization when calling a method, although there is access to the WSDL.
The magic is:
ini_set("soap.wsdl_cache_enabled", "0");
$client = new SoapClient($location, array('trace' => $trace, 'login' => $login, 'password' => $pass, 'soap_version' => 'SOAP_1_1'); //пробовал не указывать soap_version, а так же задавать параметр '1.1'
//Объект создался корректно, достучались до WSDL
$funcs = $client->__getFunctions();
//Список функций получаем корректно
try {
$request = $client->method_name(array('RegistryNumber' => $this->_RegistryNumber));
// Ответ - "SoapFault: Not Allowed"
} catch (SoapFault $exception) {
$last_request = $client->__getLastRequest();
$test = $client->__doRequest($last_request, '$location','method_name','1.1');
//Корректный ответ в XML формате
}
object(Zh_Model_SoapClient)[55]
public '_login' => string 'ХХХХ' (length=4)
public '_password' => string 'ХХХХ' (length=16)
public 'trace' => int 1
public '_soap_version' => int 1
public 'sdl' => resource(123, Unknown)
public '__default_headers' =>
array (size=1)
0 =>
object(SoapHeader)[61]
public 'namespace' => string 'ХХХХХ' (length=51)
public 'name' => string 'RequestHeader' (length=13)
public 'data' =>
object(SoapVar)[60]
...
public 'mustUnderstand' => boolean false
object(Zh_Model_SoapClient)[55]
public '_login' => string 'ХХХХ' (length=4)
public '_password' => string 'ХХХХ' (length=16)
public 'trace' => int 1
public '_soap_version' => int 1
public 'sdl' => resource(123, Unknown)
public '__default_headers' =>
array (size=1)
0 =>
object(SoapHeader)[61]
public 'namespace' => string 'ХХХХ' (length=51)
public 'name' => string 'RequestHeader' (length=13)
public 'data' =>
object(SoapVar)[60]
...
public 'mustUnderstand' => boolean false
public '__last_request' => string 'ХХХХХ'... (length=652)
public 'httpsocket' => resource(126, stream)
public '_use_proxy' => int 0
public 'httpurl' => resource(128, Unknown)
public '__last_request_headers' => string 'POST /404/ HTTP/1.1
Host: ХХХХ
Connection: Keep-Alive
User-Agent: PHP-SOAP/5.5.13
Content-Type: text/xml; charset=utf-8
SOAPAction: "urn:method_name"
Content-Length: 652
Authorization: Basic ХХХХХ
' (length=244)
public '__last_response_headers' => string 'HTTP/1.1 405 Not Allowed
Server: nginx
Date: Wed, 12 Aug 2015 03:22:39 GMT
Content-Type: text/html
Content-Length: 166
Connection: keep-alive
' (length=148)
public '__soap_fault' =>
object(SoapFault)[56]
protected 'message' => string 'Not Allowed' (length=11)
private 'string' (Exception) => string '' (length=0)
protected 'code' => int 0
protected 'file' => string 'ХХХХ' (length=63)
protected 'line' => int 83
private 'trace' (Exception) =>
array (size=10)
0 =>
array (size=4)
...
9 =>
array (size=6)
...
private 'previous' (Exception) => null
public 'faultstring' => string 'Not Allowed' (length=11)
public 'faultcode' => string 'HTTP' (length=4)
public 'xdebug_message' => string '<tr><th align='left' bgcolor='#f57900' colspan="5"><span style='background-color: #cc0000; color: #fce94f; font-size: x-large;'>( ! )</span> SoapFault: Not Allowed in ХХХ</th></tr>
<tr><th align='left' bgcolor='#e9b96e' colspan='5'>Call Stack</th></tr>
<tr><th align='center' bgcolor='#eeeeec'>#</th><th align='left' bgcolor='#eeeeec'>Time</th><th align='left' bgcolor='#eeeeec'>Memory</th><th align='left' bgcolor='#eeeeec'>Function<'... (length=4255)
Answer the question
In order to leave comments, you need to log in
$client = new SoapClient($location, array('trace' => $trace, 'location'=>$location, 'login' => $login, 'password' => $pass));
Попробуйте отладить запрос через любой GUI-клиент (например, SoapUI) и последить за заголовками.
P.S. странный запрос, никакого редиректа не просходит ли?
__last_request_headers => POST /404/ HTTP/1.1
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question