开发者

Sending HTTP requests from App Engine

Is it possible to send HTT开发者_如何学PythonP requests from my AppEngine application? I need to make some requests and pull some data from the other sites.


Yes. More info here: http://code.google.com/appengine/docs/python/urlfetch/overview.html

You can use the Python standard libraries urllib, urllib2 or httplib to make HTTP requests. When running in App Engine, these libraries perform HTTP requests using App Engine's URL fetch service, which runs on Google's scalable HTTP request infrastructure.

Here's an example:

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)
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜