Tak
Tak

Reputation: 3

How to send mix of GET and POST in python

I'm trying to send a mix of GET and POST to a URL using requests module. Is there a way to do this?

What I 've tried is the following:

import requests

payload = {'test': 'test'}
r = requests.post("http://httpbin.org/post?key1=val1&key2=val2",params=payload)

print r.text 

but when I see what is actually being sent to the server (i.e. r.text), I see that everything is being sent via POST.

Could someone tell me how I can get key1 and key2 to get sent via GET and test to be sent via POST please?

I tried to look for this on Google and on StackOveflow but couldn't find anything...

EDIT: To clarify what I'm attempting to do, what I would like is to replicate the following request that gets sent to a website: https://dl.dropboxusercontent.com/u/638729/Screen%20Shot%202015-06-04%20at%2008.43.49.png

Thank you Tak

Upvotes: 0

Views: 1407

Answers (1)

Robᵩ
Robᵩ

Reputation: 168586

You can't literally have what you ask for. A request is either GET or POST, not both. However, I think you are asking if some of the parameters can be encoded in the URL while others are form-encoded in the payload.

Try this:

import requests

params = {'key1':'val1', 'key2':'val2'}
payload = {'test': 'test'}
r = requests.post("http://httpbin.org/post",params=params,data=payload)

print r.text

Upvotes: 3

Related Questions