0
I’m putting together a list of objects to post to an API in made in Arabic, but I can’t convert the data to work on the API. In python the list of objects is something like:
payload = [
{"nome":"Flávio", "email":"[email protected]"},
{"nome":"novo", "email":"[email protected]"}
]
I’m using the python request library to send: Code of the python script
headers = {
'Content-Type': 'application/x-www-form-urlencoded',
'User-Agent': 'Mozilla/5.0',
'Authorization': token
}
requests.post(url, data=json.dumps(payload), headers=headers)
In API with Laravel I get so:
public function imporUsers(Request $request)
{
$data = ($request->getContent());
return $data;
}
But the answer I have is a Sring equal to payload I informed the above and I can’t get the data with a $data[0]['nome']
for example.
I tried to make a json_decode, but it gives an error saying that the entered parameter is wrong.
I need to turn this string into a php array to access the key and value.
Try to change the
Content-type
forapplication/json
– rafaelncarvalho