I'm using aiohttp (and asyncio) to make a POST request to a PHP application.
When I set the header for json on python the PHP application do not receive any $_POST data (PHP have Content-Type: application/json
header setted).
The php side code just returns the json_encode($_POST)
.
#!/usr/bin/env python3
import asyncio
import simplejson as json
from aiohttp import ClientSession
from aiohttp import Timeout
h = {'Content-Type': 'application/json'}
url = "https://url.php"
d = {'some': 'data'}
d = json.dumps(d)
# send JWS cookie
cookies = dict(sessionID='my-valid-jws')
async def send_post():
with Timeout(5):
async with ClientSession(cookies=cookies, headers=h) as session:
async with session.post(url, data=d) as response:
if (response.status == 200):
response = await response.json()
print(response)
loop = asyncio.get_event_loop()
loop.run_until_complete(send_post())
Running this I got: []
When removing the headers param and the json.dump(d)
I get: {"some:"data"}