【发布时间】:2010-05-14 22:04:46
【问题描述】:
是否可以从我的 AppEngine 应用程序发送 HTTP 请求?我需要提出一些请求并从其他站点提取一些数据。
【问题讨论】:
是否可以从我的 AppEngine 应用程序发送 HTTP 请求?我需要提出一些请求并从其他站点提取一些数据。
【问题讨论】:
是的。更多信息在这里: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)
【讨论】: