使用AppEngine发送具有相同名称的多个POST数据项 [英] Sending multiple POST data items with the same name, using AppEngine

查看:93
本文介绍了使用AppEngine发送具有相同名称的多个POST数据项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试使用AppEngine中的urlfetch将POST数据发送到服务器。其中一些POST数据项具有相同的名称,但具有不同的值。

I try to send POST data to a server using urlfetch in AppEngine. Some of these POST-data items has the same name, but with different values.

form_fields = {
   "data": "foo",
   "data": "bar"
}

form_data = urllib.urlencode(form_fields)
result = urlfetch.fetch(url="http://www.foo.com/", payload=form_data, method=urlfetch.POST, headers={'Content-Type': 'application/x-www-form-urlencoded'})

但是,在本例中,服务器似乎只接收一个名为 data ,值为 bar 。如何解决这个问题?

However, in this example, the server seems to receieve only one item named data, with the value bar. How could I solve this problem?

推荐答案

修改您的 form_fields 字典将具有相同名称的字段转换为列表,并使用 doseq 参数指向 urllib.urlencode

Modify your form_fields dictionary so that fields with the same name are turned into lists, and use the doseq argument to urllib.urlencode:

form_fields = {
   "data": ["foo","bar"]
}

form_data = urllib.urlencode(form_fields, doseq=True)

此时, code> form_data 'data = foo& data = bar',这是我认为您需要的。

At this point, form_data is 'data=foo&data=bar', which is what I think you need.

这篇关于使用AppEngine发送具有相同名称的多个POST数据项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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