Hick
Hick

Reputation: 36404

How do I send a query string in post request in Python using pipe delimiters?

The query string for the ASP page is sent by url?string=username|password where string=username|password is urlencoded. I'm quite confused as to achieve this in Python Requests module. This is the url:

example.asp?options=2

with parameters string=username|password

basically, the "security" feature of the api during POST is that the parameters shouldn't show in the url.

Upvotes: 2

Views: 6472

Answers (2)

Lukasa
Lukasa

Reputation: 15518

Requests automatically urlencodes POSTed data: just provide it in a dictionary. The correct code is this:

>>> data = {'string': username + '|' + password}
>>> r = requests.post(url, data=data)

Upvotes: 4

flyer
flyer

Reputation: 9816

Just use the requests.get() function because when you request a url like what you have indicated, it use the GET http method.

I haven't encounted the situation that if the url like url?string=username uses a POST http method and if it does use POST method, then use requests.post() function like this:

>>> payload = {'key1': 'value1', 'key2': 'value2'}
>>> r = requests.post("http://httpbin.org/post", data=payload)

Upvotes: -1

Related Questions