龙之吻:
You can use the Python standard libraries urllib, urllib2 or httplib to make HTTP requests……
[阅读: 263] 2009-02-25 03:17:40
App Engine applications can communicate with other applications or access other resources on the web by fetching URLs. This is useful for communicating with web services or retrieving RSS feed data.
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.
import urllib2
url = "http://www.google.com/"
try:
result = urllib2.urlopen(url)
doSomethingWithResult(result)
except urllib2.URLError, e:
handleError(e)
You can also access the URL fetch service using its Python API. In this API, the urlfetch.fetch() function performs an HTTP request.
from google.appengine.api import urlfetch
url = "http://www.google.com/"
result = urlfetch.fetch(url)
if result.status_code == 200:
doSomethingWithResult(result.content)
The URL fetch service supports five HTTP methods: GET, POST, HEAD, PUT and DELETE. The request can include HTTP headers, and body content for a POST or PUT request. For example, to submit data to a web form handler using the POST action using the URL fetch API:
import urllib
form_fields = {
"first_name": "Albert",
"last_name": "Johnson",
"email_address": "Albert.Johnson@example.com"
}
form_data = urllib.urlencode(form_fields)
result = urlfetch.fetch(url=url,
payload=form_data,
method=urlfetch.POST,
headers={'Content-Type': 'application/x-www-form-urlencoded'})
机器人,
这首歌学会了没有?
我们的目标是->没有蛀牙!