php fills $_POST data instead of php://input

Oleksandr IY

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?

Drakes

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"]);.

이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.

침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제

에서 수정
0

몇 마디 만하겠습니다

0리뷰
로그인참여 후 검토

관련 기사

분류에서Dev

PHP: not able to POST data?

분류에서Dev

php change post data to variable

분류에서Dev

implode input names from $_POST in php

분류에서Dev

How to receive array data from post in php?

분류에서Dev

Show post data to a PHP page securely

분류에서Dev

PHP validating user input data step by step

분류에서Dev

Check input data by MySQL schema or PHP?

분류에서Dev

AJAX Post to .PHP to JSON Data-set || PHP 파일

분류에서Dev

php - curl POST User Input and Hard-coded Query

분류에서Dev

Reading multipart/form-data POST data in PHP

분류에서Dev

HTML - collect data with php from a textfield out of the post <form>

분류에서Dev

Reading non key/value POST data from PHP

분류에서Dev

Sending http post request to php with many data using angular

분류에서Dev

How to send input file data value using ajax to a php page

분류에서Dev

PHP $ _POST 한도

분류에서Dev

javascript php post undefined

분류에서Dev

JSON POST using PHP

분류에서Dev

PHP form post to database

분류에서Dev

Php : Post a list of checkboxes

분류에서Dev

$ _POST PHP 고장

분류에서Dev

PHP AJAX POST 값

분류에서Dev

methode $ _POST is empty php

분류에서Dev

PHP echo in footer instead of body

분류에서Dev

`php : // input` 및 / 또는`$ _POST`를 사용해야합니까?

분류에서Dev

Data Table input type as text instead of search

분류에서Dev

Get $Post in PHP with Dot in the name

분류에서Dev

PHP에서 POST / GET

분류에서Dev

$_POST undefined index PHP error

분류에서Dev

php variables and forms method POST