V
V
Vladimir2019-04-29 16:19:15
PHP
Vladimir, 2019-04-29 16:19:15

Why is there only one response to a curl request in the console, and another in the browser via php curl?

If you make a request through the console

curl -X POST --header 'Content-Type: application/x-www-form-urlencoded' 'https://integration.cdek.ru/new_orders.php' -d 'xml_request=<?xml version="1.0" encoding="UTF-8" ?><DeliveryRequest Number="0000033876WO" Date="2019-04-25T09:09:57" Account="2Jew*******8NCbIIbKAw2" Secure="db255be********60f3c64b70" OrderCount="1"><Order Number="1448" SendCityPostCode="350000" RecCityPostCode="350000" RecipientName="Герусов Александр Валерьевич" RecipientEmail="[email protected]" Phone="89615096005" TariffTypeCode="136" DeliveryRecipientCost="137" DeliveryRecipientVATRate="VATX" DeliveryRecipientVATSum="0" SellerName="ИП Волженин Е.Г." SellerAddress="Ленинградская обл, Всеволожский р-н, Пос. Лесное, дом № 18, кв.6"><Address PvzCode="KSD5"/><Package Number="1" BarCode="krd61927-1" Weight="1000"><Item WareKey="158308" Cost="790" Payment="790" PaymentVATRate="VATX" PaymentVATSum="0" Weight="1000" Amount="1" Comment="Кронштейн для телевизора Ultramounts UM 814F черный"/></Package></Order></DeliveryRequest>'

Then the answer comes normal
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
  <response>
    <Order DispatchNumber="1119372681" Number="1448"/>
    <Order Msg="Добавлено заказов 1"/>
    <TraceId>faa62822e1c0d248</TraceId>
  </response>

And if you do it through php and display it in the browser
$request = '<?xml version="1.0" encoding="UTF-8" ?><DeliveryRequest Number="0000033876WO" Date="2019-04-29T11:22:43" Account="2JewP******NCbIIbKAw2" Secure="4a3ac********bc5f" OrderCount="1"><Order Number="1520" SendCityPostCode="350000" RecCityPostCode="350000" RecipientName="Герусов Александр Валерьевич" RecipientEmail="[email protected]" Phone="89615096005" TariffTypeCode="136" DeliveryRecipientCost="137" DeliveryRecipientVATRate="VATX" DeliveryRecipientVATSum="0" SellerName="ИП Волженин Е.Г." SellerAddress="Ленинградская обл, Всеволожский р-н, Пос. Лесное, дом № 18, кв.6"><Address PvzCode="KSD5"/><Package Number="1" BarCode="krd61927-1" Weight="1000"><Item WareKey="158308" Cost="790" Payment="790" PaymentVATRate="VATX" PaymentVATSum="0" Weight="1000" Amount="1" Comment="Кронштейн для телевизора Ultramounts UM 814F черный"/></Package></Order></DeliveryRequest>';

$host_api = 'https://integration.cdek.ru/new_orders.php';
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $host_api);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_HTTPHEADER, [
  'Content-Type: application/x-www-form-urlencoded'
  ]
);
curl_setopt($curl, CURLOPT_HEADER, 1);
curl_setopt($curl, CURLOPT_POST, 1);
curl_setopt($curl, CURLOPT_POSTFIELDS, 'xml_request=' . $request);
$response = curl_exec($curl);
if ($response === false) { 
    echo "cURL Error: " . curl_error($curl); 
}
$sent_headers = curl_getinfo($curl, CURLINFO_HEADER_OUT);
curl_close($curl);
echo "<pre>";
var_dump($response);
echo "</pre>";

I receive an answer
string(534) "HTTP/1.1 200 OK
Server: nginx
Date: Mon, 29 Apr 2019 12:43:58 GMT
Content-Type: text/xml; charset=UTF-8
Content-Length: 356
Connection: keep-alive
Vary: Accept-Encoding

1fd3464******cda0"

Both options work, but I need the same answer to be displayed on the screen as in the console

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
Rsa97, 2019-04-29
@Rsa97

$request = '<?xml version="1.0" encoding="UTF-8" ?><DeliveryRequest Number="0000033876WO" Date="2019-04-29T11:22:43" Account="2JewP******NCbIIbKAw2" Secure="4a3ac********bc5f" OrderCount="1"><Order Number="1520" SendCityPostCode="350000" RecCityPostCode="350000" RecipientName="Герусов Александр Валерьевич" RecipientEmail="[email protected]" Phone="89615096005" TariffTypeCode="136" DeliveryRecipientCost="137" DeliveryRecipientVATRate="VATX" DeliveryRecipientVATSum="0" SellerName="ИП Волженин Е.Г." SellerAddress="Ленинградская обл, Всеволожский р-н, Пос. Лесное, дом № 18, кв.6"><Address PvzCode="KSD5"/><Package Number="1" BarCode="krd61927-1" Weight="1000"><Item WareKey="158308" Cost="790" Payment="790" PaymentVATRate="VATX" PaymentVATSum="0" Weight="1000" Amount="1" Comment="Кронштейн для телевизора Ultramounts UM 814F черный"/></Package></Order></DeliveryRequest>';

$host_api = 'https://integration.cdek.ru/new_orders.php';
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $host_api);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_POST, 1);
curl_setopt($curl, CURLOPT_POSTFIELDS, ['xml_request' => $request]);
$response = curl_exec($curl);
if ($response === false) { 
    echo "cURL Error: " . curl_error($curl); 
}
$sent_headers = curl_getinfo($curl, CURLINFO_HEADER_OUT);
curl_close($curl);
echo "<pre>";
var_dump($response);
echo "</pre>";

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question