J
J
John Freeman2016-11-24 20:48:05
PHP
John Freeman, 2016-11-24 20:48:05

How to read the response from the service?

One service sends me this POST:

Array
(
    [qw] => qaz
    [qwerty] => wsx
    [qwerty2] => edc
    [qwerty3] => rfv
    [qwerty4] => tgb
    [qwerty5] => yhn
    [qwerty6] => 
)

I do like this:
parse_str(file_get_contents("php://input"),$post_vars);

$qw = $post_vars['qw'];
$qwerty = $post_vars['qwerty'];
$qwerty2 = $post_vars['qwerty2'];
$qwerty3 = $post_vars['qwerty3'];
$qwerty4 = $post_vars['qwerty4'];
$qwerty5 = $post_vars['qwerty5'];
$qwerty6 = $post_vars['qwerty6'];

and I try to write to the database, but it just writes emptiness,
but when I write the whole thing to a .txt file like this:
file_put_contents('test.txt', file_get_contents('php://input'));

then the file comes:
Array
(
    [qw] => qaz
    [qwerty] => wsx
    [qwerty2] => edc
    [qwerty3] => rfv
    [qwerty4] => tgb
    [qwerty5] => yhn
    [qwerty6] => 
)

what am I doing wrong??

Answer the question

In order to leave comments, you need to log in

2 answer(s)
I
Immortal_pony, 2016-11-24
@AsviS

I correctly understood that the service sends data in the var_dump format? Melkij
pointed out in the comments that this is more of a print_r output. Unexpectedly, but there have already been precedents. Reverse parser for var_dump from StackOverflow colleagues. A reverse parser for print_r from php.net commenters and another one from StackOverflow. Also, perhaps there is a misreading of the documentation. For example, the description of the specified service does not suspect such a response format at all:
POST - An HTTP POST to a URL of your choosing with transaction details (in either an XML or CSV format)
GET - An HTTP GET to a URL of your choosing with transaction detail you define in the query string.
Dear developers facing similar problems in the future! Make sure you understand the documentation correctly and there really is a need for such parsing tools (;

M
Melkij, 2016-11-24
@melkij

then the file comes:

So this garbage is sent to you. Instead of the normally encoded application/x-www-form-urlencoded. Kick the developers of this service to fix this idiocy.
Well, or write a parser crutch.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question