0

There is strange behavior of the php work. I pass json data via POST and expect that data appear in php://input.Instead of it fills $_POST with the strange key/value pairs. Here is curl call

$process = curl_init("https://www.myurl.com/script");
curl_setopt($process, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($process, CURLOPT_SSL_VERIFYHOST, FALSE);


$params = '{"Response":{"Data":{"RMID":"0910403545","QID":"965102499460","RspCode":"000","RspDesc":"Successful Transaction Complete","TrxID":"61801","TrxStatus":"COMPLETE","BID":"61801","TrxRC":"4201","TrxTime":"2015-06-15 14:53:51","TrxValue":"9"}},"Signature":"5bf094adb23e40e1de135c055684dd2098ab18d0","Certificate":"-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

5bf094adb23e40e1de135c055684dd2098ab18d0
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.5 (GNU/Linux)

iD8DBQFVfoSPQ8sozXgiBRURArdkAKCwx5ggf5dE+djAAMIDsHaapLRgOACePyys
a5scG9GhRFDefGz5CLHrqfI=
=AWpR
-----END PGP SIGNATURE-----
"}';

curl_setopt($process, CURLOPT_POST, true);
curl_setopt($process, CURLOPT_POSTFIELDS, $params);
curl_setopt($process, CURLOPT_RETURNTRANSFER, 1);

$return = curl_exec($process);

And on other end I get

echo "<pre>";
var_export($_POST);
---------------------------------------------
array (
  '{"Response":{"Data":{"RMID":"0910403545","QID":"965102499460","RspCode":"000","RspDesc":"Successful_Transaction_Complete","TrxID":"61801","TrxStatus":"COMPLETE","BID":"61801","TrxRC":"4201","TrxTime":"2015-06-15_14:53:51","TrxValue":"9"}},"Signature":"5bf094adb23e40e1de135c055684dd2098ab18d0","Certificate":"-----BEGIN_PGP_SIGNED_MESSAGE-----
Hash:_SHA1

5bf094adb23e40e1de135c055684dd2098ab18d0
-----BEGIN_PGP_SIGNATURE-----
Version:_GnuPG_v1_4_5_(GNU/Linux)

iD8DBQFVfoSPQ8sozXgiBRURArdkAKCwx5ggf5dE_djAAMIDsHaapLRgOACePyys
a5scG9GhRFDefGz5CLHrqfI' => '
=AWpR
-----END PGP SIGNATURE-----
"}',
)

Why does it do that?

1 Answer 1

1

Regarding curl_setopt($process, CURLOPT_POSTFIELDS, $params);

This parameter can either be passed as a urlencoded string like 'para1=val1&para2=val2&...' or as an array. (ref)

cURL is expecting a param/value pair, and you've supplied just a string, so cURL assumes the parameter is everything up to the first = sign, and the value is everything after that until the first & sign is encountered, which there aren't any. That is why $_POST looks this way when you dump it.

One way to alleviate this is to urlencode the $params string and pass it into curl_setopt like "data=".rawurlencode($params), then retrieve it using rawurldecode($_POST["data"]);.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.