JohnDotOwl
JohnDotOwl

Reputation: 3755

Issuing reading JSON from POST

This using Python's requests to post JSON to my PHP server

url = 'http://www.domain.com/ex/S/A/R/PW'
payload = {'trackingNo': 'data'}  
headers = {'content-type': 'application/json'}
datas = {'ids': [12, 3, 4, 5, 6]}
r = requests.post(url, data=json.dumps(data), headers=headers)
print(r.text)
print(r.headers)

In PHP when I try var_dump I get null. But I do receive the echo.

var_dump($_POST[ids]);
var_dump($_POST);
echo "POSTED";

Reply from PHP

NULL
array(0) {
}
POSTED

Upvotes: 1

Views: 110

Answers (2)

gentoomaniac
gentoomaniac

Reputation: 111

Typo? I guess you want to dump datas

r = requests.post(url, data=json.dumps(datas), headers=headers)

instead of

r = requests.post(url, data=json.dumps(data), headers=headers)

Upvotes: 1

Alex Kapustin
Alex Kapustin

Reputation: 2459

Try to write in PHP:

var_dump(json_decode(file_get_contents("php://input")));

Upvotes: 1

Related Questions