url = 'http://server/cgi'
data = {
"arg1" : "val1",
"arg2" : "val2"
}
發送 POST:
import urllib
from google.appengine.api import urlfetch
post_data = urllib.urlencode(data)
response = urlfetch.fetch(url=url,payload=post_data,method=urlfetch.POST,headers={'Content-Type': 'application/x-www-form-urlencoded'})
發送 JSONRPC:
import urllib2
headers = {
"Content-Type": "application/json"
}
post_data = json.dumps(data)
req = urllib2.Request(url, data, headers)
response = urllib2.urlopen(req).read()
沒有留言:
張貼留言