1

我在 Google Apps 引擎上用 Python 编写了一个非常简单的服务器。我希望能够通过 GET 请求向它发送命令,例如"http://myserver.appspot.com/?do=http://webpage.com/?secondary=parameter"

这不起作用,因为辅助参数被单独解释并发送到我的应用程序。有什么帮助吗?

4

1 回答 1

1

网址http://myserver.appspot.com/?do=http://webpage.com/?secondary=parameter格式不正确。也许您可以urlencode将字符串数据然后发送

from urllib import urlencode
data = {"do": "http://webpage.com/?secondary=parameter"}
encoded_data = urlencode(data)
url = "http://myserver.appspot.com/?" + encoded_data

给出输出

>>> print url
http://myserver.appspot.com/?do=http%3A%2F%2Fwebpage.com%2F%3Fsecondary%3Dparameter

或者,如果您使用的是 pythonrequests模块,您可以这样做

import requests
payload = {"do": "http://webpage.com/?secondary=parameter"}
r = requests.get("http://myserver.appspot.com/", params=payload)

给出输出

>>> print r.url
u'http://myserver.appspot.com/?do=http%3A%2F%2Fwebpage.com%2F%3Fsecondary%3Dparameter'
于 2014-11-11T02:45:28.783 回答