【问题标题】:Sending a URL in a GET request to a Python server on Google App Engine将 GET 请求中的 URL 发送到 Google App Engine 上的 Python 服务器
【发布时间】:2014-11-11 02:28:35
【问题描述】:

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

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

【问题讨论】:

  • 这不是关于 GAE 的问题。

标签: python google-app-engine parameters server get-request


【解决方案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

或者,如果你使用 python requests 模块,你可以这样做

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'

【讨论】:

    猜你喜欢
    • 2013-05-22
    • 2017-10-19
    • 2018-10-02
    • 1970-01-01
    • 1970-01-01
    • 2022-01-04
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多