【问题标题】:Sending HTTP requests from App Engine从 App Engine 发送 HTTP 请求
【发布时间】:2010-05-14 22:04:46
【问题描述】:

是否可以从我的 AppEngine 应用程序发送 HTTP 请求?我需要提出一些请求并从其他站点提取一些数据。

【问题讨论】:

    标签: python google-app-engine


    【解决方案1】:

    是的。更多信息在这里:http://code.google.com/appengine/docs/python/urlfetch/overview.html

    您可以使用 Python 标准 库 urllib、urllib2 或 httplib 发出 HTTP 请求。跑进去的时候 App Engine,这些库执行 使用 App Engine 网址的 HTTP 请求 fetch 服务,运行在 Google 的 可扩展的 HTTP 请求基础架构。

    这是一个例子:

    import urllib
    from xml.dom import minidom
    from google.appengine.api import urlfetch
    
    params = urllib.urlencode({'p': loc_param, 'u': units,})
    full_uri = '?'.join([url, params,])
    
    result = urlfetch.fetch(full_uri)
    if result.status_code == 200:
        return minidom.parseString(result.content)
    

    【讨论】:

    • 也可以直接使用urllib和urllib2;它们已被修补为您使用 urlfetch 服务。
    猜你喜欢
    • 1970-01-01
    • 2011-04-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多