我在Google Apps引擎上用Python编写了一个非常简单的服务器。我希望能够通过GET请求向其发送命令,例如"http://myserver.appspot.com/?do=http://webpage.com/?secondary=parameter"
这是行不通的,因为辅助参数会分别解释并发送到我的应用程序。有什么帮助吗?
网址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'
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句