Pergunta

I am using Python 2.7 with the requests module to send http post with parameters. I encountered a strange problem.

To do http post, it is just one line;

x = requests.post(URL, params)

I have no problem with the params. It is the URL that puzzled me.

Sometimes, this URL http://hostname/path/post works. Sometimes, I use http://hostname/path without the /post to get the HTTP post to work. I am puzzled why is this so. What is the difference between the two? Under what conditions do I use which one?

Foi útil?

Solução

'http://hostname/path/post' is a path. You could in principle issue and HTTP GET request to that same path (although probably you wouldn't get anything meaningful back).

In general, you should look at the site's API documentation and post to the url that they say you should post to without adding anything extra to the url.

Outras dicas

There are two different concepts, url and HTTP method. You are confused by trying to mix them.

url - an address you talk to

The url is addressing something on some server. If you get valid url, you can take it as a string, do not read in, and use it. Consider it to be a string.

If I would link it to a visiting your friend, url is address of a doors to come to.

HTTP method (POST, GET, DELETE...)

There are multiple HTTP methods which differ in the way, how you talk to given url.

Linking it to visiting a friend, it would be the way, you try to make the doors open (use the bell, knock or use a hammer)

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top