1

I want to get live rates of all shipping methods of TNT Lebanon between origin and delivery address. Like Road Express, Overnight Express, Overnight PAYU Satchel, 9:00 Express, 10:00 Express, etc.

I am using below code.

$url = 'http://app.thenetmanager.net/pos/POSWS.asmx?op=CalculatePOSOrderPrice';

$xmlRequest = "<? xml version = "1.0" encoding = "utf-8"?>
<soap12:Envelope xmlns:soap12="http://www.w3.org/2003/05/soap-envelope">
    <soap12:Body>
        <CalculatePOSOrderPrice xmlns="http://posws.org/">
            <userIdentifier>69741684-B9DA-404D-833D-1DE02F11154E</userIdentifier>
            <serviceID>70</serviceID>
            <shipperCity>LEBANON</shipperCity>
            <consigneeCountry>TRIPOLI</consigneeCountry>
            <consigneeCity>opentext</consigneeCity>
            <isDocument>false</isDocument>
            <weight>0.6</weight>
            <specialDelivery>-1</specialDelivery>
            <goodsValue>10.0</goodsValue>
            <goodsDescription>description</goodsDescription>
            <addPacking>false</addPacking>
            <addFumigation>false</addFumigation>
            <addPermit>false</addPermit>
            <addInsurance>false</addInsurance>
        </CalculatePOSOrderPrice>
    </soap12:Body>
</soap12:Envelope>";


$ch = curl_init();
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/xml'));
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $xmlRequest);
curl_setopt($ch, CURLOPT_TIMEOUT, 30);
$xmlResponse = curl_exec($ch);
print_r($xmlResponse);

But gives me an empty message.

2

I think your issue is connected with double (") quotation marks, in which you’ve wrapped your xml-request (you can also find them there). Your php-code is interpreted in a wrong way because of it and you are not getting the correct result.

phpstorm

Try to replace the double quotation marks with the with single ones (') and change:

curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/xml')); 

with:

curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: text/xml; charset=utf-8', 'Content-Length: '.strlen($xmlRequest))); 

Updated final code:

<?php
$url = 'http://app.thenetmanager.net/pos/POSWS.asmx?op=CalculatePOSOrderPrice';
        $xmlRequest = '<?xml version="1.0" encoding="utf-8"?>
<soap12:Envelope xmlns:soap12="http://www.w3.org/2003/05/soap-envelope">
    <soap12:Body>
        <CalculatePOSOrderPrice xmlns="http://posws.org/">
            <userIdentifier>69741684-B9DA-404D-833D-1DE02F11154E</userIdentifier>
            <serviceID>70</serviceID>
            <shipperCity>LEBANON</shipperCity>
            <consigneeCountry>TRIPOLI</consigneeCountry>
            <consigneeCity>opentext</consigneeCity>
            <isDocument>false</isDocument>
            <weight>0.6</weight>
            <specialDelivery>-1</specialDelivery>
            <goodsValue>10.0</goodsValue>
            <goodsDescription>description</goodsDescription>
            <addPacking>false</addPacking>
            <addFumigation>false</addFumigation>
            <addPermit>false</addPermit>
            <addInsurance>false</addInsurance>
        </CalculatePOSOrderPrice>
    </soap12:Body>
</soap12:Envelope>';
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($ch, CURLOPT_HEADER, 0);
        curl_setopt($ch, CURLOPT_POST, 1);
        curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: text/xml; charset=utf-8', 'Content-Length: '.strlen($xmlRequest)));
        curl_setopt($ch, CURLOPT_POSTFIELDS, $xmlRequest);
        curl_setopt($ch, CURLOPT_TIMEOUT, 30);
        $xmlResponse = curl_exec($ch);
        print_r($xmlResponse);
        curl_close($ch);

Result (debug):

Result

Result (plain):

<?xml version="1.0" encoding="utf-8"?><soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"><soap:Body><CalculatePOSOrderPriceResponse xmlns="http://posws.org/"><CalculatePOSOrderPriceResult>-1</CalculatePOSOrderPriceResult></CalculatePOSOrderPriceResponse></soap:Body></soap:Envelope>

PS: This is just my opinion, in case it won’t help, please, edit the code and get back here.

|improve this answer|||||
  • i got this message soap:ReceiverServer was unable to process request. ---> Name cannot begin with the ' ' character, hexadecimal value 0x20. Line 1, position 3. – mahmoudismail Apr 11 '16 at 10:07
  • @mahmoudismail > you should delete the space between <? and xml. source – Siarhey Uchukhlebau Apr 11 '16 at 10:08
  • Oki , again i got an empty message :) – mahmoudismail Apr 11 '16 at 10:12
  • @mahmoudismail I’ve updated my answer – Siarhey Uchukhlebau Apr 11 '16 at 11:01
  • 2
    You can get that from TNT Support. contact them. Regards :) – mahmoudismail Apr 20 '16 at 6:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.