Y
Y
Yaroslav2021-07-14 22:29:56
PHP
Yaroslav, 2021-07-14 22:29:56

How to handle POST request response with JSON?

Hello! I don't know what to do anymore. The bottom line is this, I send a POST request, the answer comes naturally, like this 60ef3937e45d6563346292.png.
It can be seen that the entire response, along with the headers, is in one line, and even though you crack, I can’t figure out how to get to the json itself, which is after the headers in curly braces. json_decode, (object), (array) etc don't work. I understand that you can trim the string before the opening and after the closing curly braces, but isn't there a correct way to get json from the response? Sending via curl_setopt. All in php. And, if the information is useful - the request initially comes from one service in xml, I have it parsed in json and sent via post to a third-party service, it returns in this form, which I need to parse into components and return to the first service in xml. And for the second day I can’t figure out how to get this json correctly.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
DevMan, 2021-07-14
@ManMadeMind

why do you have headlines in the answer itself?
or something is wrong on the sending side, or you are not receiving correctly.
wangyu: uses curl with the option to get headers.

A
Adamos, 2021-07-14
@Adamos

$lines = explode("\r\n", $yourAwfulString);
$json = $lines[count($lines) - 2);
$result = json_decode($json);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question