0

I am trying to query a server with a POST method in Python.

import requests

url  = "https://www.test.com/service"
data = {"param": "value"}

req = requests.post(url, data).content

When I look at req, it clearly doesn't take into account the data I posted.

If I check the header with cURL:

curl -ik -X POST -d "param=value" https://www.test.com/service

I get the following HTTP 302:

HTTP/1.1 302 Déplacé Temporairement
Date: Fri, 06 Oct 2017 16:42:36 GMT
Server: Apache-Coyote/1.1
X-Content-Type-Options: nosniff
X-XSS-Protection: 1; mode=block
Cache-Control: no-cache, no-store, max-age=0, must-revalidate
Pragma: no-cache
Expires: 0
Location: https://www.test.com/redirect
Content-Language: fr-FR
Content-Length: 0
Via: 1.1 www.test.com

So if I understand well, I am redirected to Location which is https://www.test.com/redirect. This address can only be query with a GET method; if I try with a POST, I get a HTTP 500 error.

What I understand thus is that I am POSTing a request with parameters and I am redirected to another page and the request becomes a GET, querying Location. I don't understand then what happens to my parameters: in my browser, I get an answer that takes into account the parameters sent, when I query it by hand they seem to be "lost" since I just get kind of an empty version of https://www.test.com/redirect.

What do I miss? My understanding of requests is pretty shallow so I'm sure I'm missing something obvious.

MBR
  • 794
  • 13
  • 34

1 Answers1

0

Correct syntax to use requests.post. requests

import requests

url  = "https://www.test.com/service"
data = {"param":"value"}

req = requests.post(url, data).content
Dharmesh Fumakiya
  • 2,276
  • 2
  • 11
  • 17
  • I edited my question, it was an unfortunate typo. I doesn't work with the correct syntax, I do have this issue. If I had done this mistake, from [my experience](https://stackoverflow.com/questions/46422307/post-method-in-python-errno-104), it should else trigger a `104 error`! – MBR Oct 06 '17 at 17:19