Sending HTTP requests from App Engine

2019-04-14 03:09发布

Is it possible to send HTTP requests from my AppEngine application? I need to make some requests and pull some data from the other sites.

1条回答
时光不老,我们不散
2楼-- · 2019-04-14 03:32

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)
查看更多
登录 后发表回答