2015-06-26 26 views
10

Dostaję poniżej błędu po żądaniu wywołania SOAP.SOAP: HTTP Bad Request

fault code: HTTP, fault string: Bad Request

Czy to źle sformułowana wiadomość?

try{ 
    $client = new SoapClient("http://ip_add/something.asmx?WSDL", array("trace" => true, 'exceptions' => 1)); 

    $params = new \SoapVar('<?xml version="1.0" encoding="utf-8"?> 
       <soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"> 
       <soap:Body> 
        <RemittanceService xmlns="http://tempuri.org/"> 
        <CreditTxnMessage xmlns="http://my_url"> 
        <Corporate_UID xmlns="">66666</Corporate_UID> 
        <Mandate_Type xmlns="">P</Mandate_Type> 
        <MICR_No xsi:nil="true" xmlns="" /> 
        <Instrument_No xsi:nil="true" xmlns="" /> 
        <Remitter_Address1 xmlns="">285 enfiled pl</Remitter_Address1> 
        <Remitter_Address2 xmlns="">mississauga</Remitter_Address2> 
        <Remitter_Address3 xmlns="">16y2n4</Remitter_Address3> 
        <Remitter_Country xmlns="">Canada</Remitter_Country> 
        <Remitter_ZIP_Code xsi:nil="true" xmlns="" /> 
        <Remitter_EmailID xsi:nil="true" xmlns="" /> 
        <Remitter_Contact_No xmlns="" /> 
        <Beneficiary_ZIP_Code xsi:nil="true" xmlns="" /> 
        <Beneficiary_EmailID xsi:nil="true" xmlns="" /> 
        <Beneficiary_Contact_No xmlns="" /> 
        <Beneficiary_Bank_Name xmlns="">PNB</Beneficiary_Bank_Name> 
        </CreditTxnMessage> 
        </RemittanceService> 
       </soap:Body> 
       </soap:Envelope>', XSD_ANYXML); 

    $result = $client->__soapCall('RemittanceService', array($params)); 
    highlight_string($client->__getLastRequest()); 
} 
catch(SoapFault $fault){ 
    die("SOAP Fault:<br />fault code: {$fault->faultcode}, fault string: {$fault->faultstring}"); 
} 

Nie wiem, co jest nie tak.

Śledzenie stosu

SoapFault exception: [HTTP] Bad Request in /var/www/mtes/public_html/application/controllers/bank_api_pnb.php:146 
Stack trace: 
#0 [internal function]: SoapClient->__doRequest('<?xml version="...', 'http://124.124....', 'http://tempuri....', 1, 0) 
#1 /var/www/mtes/public_html/application/controllers/bank_api_pnb.php(146): SoapClient->__soapCall('RemittanceServi...', Array) 
#2 [internal function]: Bank_api_pnb->test() 
#3 /var/www/mtes/public_html/system/core/CodeIgniter.php(359): call_user_func_array(Array, Array) 
#4 /var/www/mtes/public_html/index.php(220): require_once('/var/www/mtes/p...') 
#5 {main} 
+0

try {// ...} catch (SoapFault $ e) { \t echo $ e-> getMessage(); # Sprawdź błąd msg } – PHPJungle

+0

Mówi: Złe żądanie. 'faultstring' i' getMessage() 'są takie same. –

+0

Czy masz serwer proxy?Sugeruję użycie Fiddlera do przechwytywania żądania HTTP, a następnie sprawdź odpowiedź serwera. – PHPJungle

Odpowiedz

5

Cały punkt SoapClient polega na konwersji wywołań do xml; więc nie powinieneś robić tego ręcznie. Spróbuj zamiast tego:

try { 
    $client = new SoapClient("http://ip_add/something.asmx?WSDL", array("trace" => true, 'exceptions' => 1)); 

    $result = $client->RemittanceService(array(
      'CreditTxnMessage' => array(
        'Corporate_UID' => 66666, 
        'Mandate_Type' => 'P', 
        'MICR_No' => null, 
        /* you get the idea */ 
        'Beneficiary_Contact_No' => '', 
        'Beneficiary_Bank_Name' => 'PNB' 
      ) 
    )); 

    highlight_string($client->__getLastRequest()); 
} 
catch(SoapFault $fault){ 
    die("SOAP Fault:<br />fault code: {$fault->faultcode}, fault string: {$fault->faultstring}"); 
} 

Dokładny format parametrów i ich nazwy zostaną określone w pliku WSDL.

+0

Wreszcie dostałem rozwiązanie. Dzięki. –

3

Generalnie odpowiedź Bad Request na żądanie SOAP jest zwracany, gdy wiadomość nie jest w dobrej formie (nieprawidłowy nagłówek, ciało, ..) i do nich dokument nie może zostać sparsowane. Przede wszystkim staramy się usunąć deklarację wersji XML z SoapVar i zobacz, czy to rozwiązuje problem (usunąć poniższy wiersz):

<?xml version="1.0" encoding="UTF-8"?> 

Alternatywnie można zawsze sprawdzić swoje żądania mydło w narzędzia jak SoapUI aby upewnić się, że pracować, a następnie dokończyć swój kod. Jeśli nie działa w SoapUI, oznacza to, że coś jest nie tak z żądaniem. Spróbuj skorygować WS i upewnij się, że wysyłasz wszystko w odpowiednim formacie (np. Może musisz uwierzytelnić? SoapHeader? ..)

+0

Próbowałem usunąć powyższy wiersz z wiadomości 'SOAP'. Nie, w Daje mi ten błąd: 'Wyjątek jest zgłaszany przez Harmonogram Orkiestracji ' –

+0

I nie mogę go sprawdzić na' SOAPUI', ponieważ nasz klient ograniczył dostęp SOAP tylko do adresu IP naszego serwera. –

1

Nie jestem zaznajomiony z PHP, ale spróbuj tego.

$Request = '<RemittanceService xmlns="http://tempuri.org/"> 
        <CreditTxnMessage xmlns="http://my_url"> 
        <Corporate_UID xmlns="">66666</Corporate_UID> 
        <Mandate_Type xmlns="">P</Mandate_Type> 
        <MICR_No xsi:nil="true" xmlns="" /> 
        <Instrument_No xsi:nil="true" xmlns="" /> 
        <Remitter_Address1 xmlns="">285 enfiled pl</Remitter_Address1> 
        <Remitter_Address2 xmlns="">mississauga</Remitter_Address2> 
        <Remitter_Address3 xmlns="">16y2n4</Remitter_Address3> 
        <Remitter_Country xmlns="">Canada</Remitter_Country> 
        <Remitter_ZIP_Code xsi:nil="true" xmlns="" /> 
        <Remitter_EmailID xsi:nil="true" xmlns="" /> 
        <Remitter_Contact_No xmlns="" /> 
        <Beneficiary_ZIP_Code xsi:nil="true" xmlns="" /> 
        <Beneficiary_EmailID xsi:nil="true" xmlns="" /> 
        <Beneficiary_Contact_No xmlns="" /> 
        <Beneficiary_Bank_Name xmlns="">PNB</Beneficiary_Bank_Name> 
        </CreditTxnMessage> 
        </RemittanceService>'; 
$result = $client->__doRequest($Request, "http://ip_add/something.asmx", "RemittanceService", soap_1_2, 0); 
+0

Użyłem 'SOAP_1_1' i otrzymuję tę odpowiedź:' mydło : Klient Serwer nie rozpoznał wartości nagłówka HTTP SOAPAction: usługa wymiany. ' –

+0

Spróbuj wpisać pełny adres URL działania:' "http://tempuri.org/RemittanceService "' –

1

Nie jestem pewien jak działa SoapVar, ale odradzam przekazywanie surowego XML do SoapClient. Chciałbym spróbować odtworzyć strukturę XML w tablic PHP (bolesne, wiem), zwłaszcza, że ​​XML pojawia się w ślad stosu:

$params = array(
    "RemittanceService" => array("xmlns"=>"http://tempuri.org/", "_" => array(
     "CreditTxnMessage" => array("xmlns" => "http://my_url", "_" => array(
      "Corporate_UID" => array("xmlns" => "", "_" => 66666), 
      "Mandate_Type" => array("xmlns" => "", "_" => "P"), 
      "MICR_No" => array("xsi:nil" => "true", "xmlns" => ""), 
      // and so on... 
     )) 
    )) 
); 

Również powinieneś określić wersję SOAP (SOAP_1_1 lub SOAP_1_2) w konstruktor SoapClient:

$client = new SoapClient("http://ip_add/something.asmx?WSDL", array('soap_version' => SOAP_1_2, "trace" => true, 'exceptions' => 1)); 

również tablica argumentów w __soapCall() jest dość wybredny o formatowaniu. Spróbuj wykonać następujące czynności:

$result = $client->__soapCall('RemittanceService', array('parameters' => $params)); 

lub nawet:

$result = $client->__soapCall('RemittanceService', $params); 

Ja w zasadzie zgadywania, co problem jest, więc to nie jest bardzo dokładne rozwiązanie. Możesz także spróbować spojrzeć gdzie indziej na SO. Na przykład this answer używa SoapVar.

Powiązane problemy