K
K
Konstantin Smetana2015-09-21 17:20:51
PHP
Konstantin Smetana, 2015-09-21 17:20:51

How to convert curl request to SOAP Client php?

There is this code:

curl -H "Content-Type: text/xml; charset=utf-8" \
     -H "SOAPAction: \"http://www.example.com/contractor/dtaservice/v7/contractorservice/GetProductCatalog\"" \
     -d @$3 \
     -X POST http://$1:$2/DTAContractor/Service/ContractorSystemService

where, $1 = ip,
$2 = port,
$3 = xml file:
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
    <s:Header>
        <h:AuthenticationHeader xmlns:h="http://www.example.com/contractor/dtaservice/v7/contractorheader" xmlns="http://www.example.com/contractor/dtaservice/v7/contractorheader" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
            <ClientId>ID</ClientId>
            <UserName>USER</UserName>
            <Password>PASS</Password>
        </h:AuthenticationHeader>
    </s:Header>
    <s:Body xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
        <GetProductCatalogRequest xmlns="http://www.example.com/contractor/dtaservice/v7/contractormessages" />
    </s:Body>
</s:Envelope>

Tried like this:
$location = 'http://'.$ip.':'.$port.'/DTAContractor/Service/ContractorSystemService';
$uri = 'http://www.example.com/contractor/dtaservice/v7/contractorservice/GetProductCatalog';
$ns = 'http://www.example.com/contractor/dtaservice/v7/contractorheader';
$soap = new SoapClient(null, array('location' => $location, 'uri' => $uri, 'trace' => 1));

$headerBody = array(
            'ClientId'  => $clientId,
            'UserName'  => $userName,
            'Password'  => $password,
        );

$soapHeader = new SoapHeader($ns, 'AuthenticationHeader', $headerBody);
$soap->__setSoapHeaders($soapHeader);
$soap->GetProductCatalogRequest();

I get the error: User Error: SOAP-Fehler: (Fehlernummer: HTTP, Fehlermeldung: Could not connect to host)
What am I doing wrong? Thank you!

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question