如何在python中发送GET和POST的混合 [英] How to send mix of GET and POST in python

查看:73
本文介绍了如何在python中发送GET和POST的混合的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用请求模块将GET和POST的组合发送到URL.有办法吗?

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

我尝试过以下操作:

import requests

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

print r.text 

但是当我看到实际发送到服务器的内容(即r.text)时,我看到一切都是通过POST发送的.

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.

请问有人可以告诉我如何通过GET发送key1和key2并通过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?

我试图在Google和StackOveflow上寻找它,但找不到任何东西...

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

要弄清我要做什么,我想要复制发送到网站的以下请求:

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

谢谢达

推荐答案

您无法真正获得所需的内容.一个请求要么是GET要么是POST,而不是两者.但是,我认为,您是在询问某些参数是否可以在URL中进行编码,而其他参数是否可以在有效负载中进行形式编码.

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.

尝试一下:

import requests

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

print r.text

这篇关于如何在python中发送GET和POST的混合的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆