V
V
Vladimir Miroshnik2020-04-20 13:41:26
PHP
Vladimir Miroshnik, 2020-04-20 13:41:26

How to remove server header from curl response and get json?

Good afternoon!

There is a curl request code:

$ch = curl_init($host);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json', 'Content-Length: ' . strlen($data_string), 'Accept: application/json'));
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLOPT_USERPWD, $username . ":" . $password);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
$return = curl_exec($ch);
curl_close($ch);


It produces this result:

HTTP/1.1 200 OK Server: nginx Date: Mon, 20 Apr 2020 10:36:28 GMT Content-Type: application/json; charset=utf-8 Content-Length: 1691 Connection: keep-alive Cache-Control: private {"Model":{"ReasonCode":0,"PublicId":"pk_474a2da14ee45cb9a6834cbf9da55","TransactionId":337858838,"Amount":1,"Currency":"RUB","CurrencyCode":0,"PaymentAmount":1,"PaymentCurrency":"RUB","PaymentCurrencyCode":0,"InvoiceId":null,"AccountId":"[email protected]","Email":"[email protected]","Description":"Подписка на Город Фотографов","JsonData":"{\"course_id\":13,\"potok_number\":1,\"tarif\":0,\"number\":\"79313074592\",\"name\":\"Владимир\"}","CreatedDate":"\/Date(1585668931956)\/","PayoutDate":"\/Date(1586120400000)\/","PayoutDateIso":"2020-04-05T21:00:00","PayoutAmount":-2.9,"CreatedDateIso":"2020-03-31T15:35:31","AuthDate":"\/Date(1585668933061)\/","AuthDateIso":"2020-03-31T15:35:33","ConfirmDate":"\/Date(1586106605386)\/","ConfirmDateIso":"2020-04-05T17:10:05","AuthCode":"058813","TestMode":false,"Rrn":"221348325946","OriginalTransactionId":null,"IpAddress":"89.179.187.11","IpCountry":"RU","IpCity":"Москва","IpRegion":"Москва","IpDistrict":"Центральный федеральный округ","IpLatitude":55.755787,"IpLongitude":37.617634,"CardFirstSix":"547127","CardLastFour":"9200","CardExpDate":"11/22","CardType":"MasterCard","CardProduct":"TNW","CardCategory":"MASTERCARD NEW WORLD IMMEDIATE DEBIT ()","IssuerBankCountry":"RU","Issuer":"TINKOFF BANK","CardTypeCode":1,"Status":"Completed","StatusCode":3,"CultureName":"ru","Reason":"Approved","CardHolderMessage":"Оплата успешно проведена","Type":0,"Refunded":false,"Name":null,"Token":"619755374","SubscriptionId":null,"GatewayName":"Tinkoff","ApplePay":true,"AndroidPay":false,"TotalFee":0},"InnerResult":null,"Success":true,"Message":null}


How can I remove the line "HTTP/1.1 200 O..." etc. so that I get only json, without server headers?

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