#GET:
#!/usr/bin/env python
#-*-Coding:utf-8-*-
import Urllib2
def ():
URL = ' www.baidu.com ' #页面的地址
Response = Urllib2. (url) # Call Urllib2 to send a GET request to the server
return response read () #获取服务器返回的页面信息
#POST:
#!/usr/bin/env python
#-*-Coding:utf-8-*-
Import Urllib
Import Urllib2
def Post():
Url= ' http://umbra.nascom.nasa.gov/cgi-bin/eit-catalog.cgi ' #页面的地址
Values= {' Obs_year ':' 2011 ',' Obs_month ':' March ',#post的值
' Obs_day ':' 8 ',' Start_year ':' 2011 '
,' Start_month ':' March ',' Start_day ':' 8 '
,' Start_hour ':' All Hours ',' Stop_year ':' 2011 '
,' Stop_month ':' March ',' Stop_day ':' 8 '
,' Stop_hour ':' All Hours ',' Xsize ':' All '
, ' ysize ' : ' all ' , ' wave ' : ' all '
, ' filter ' : ' all ' , ' object ' :< span class= "str" > ' all '
, ' xbin ' : ' all ' , ' ybin ' : ' all '
,' HIGHC ':' All '}
Data=Urllib.UrlEncode(Values)#适用urllib对数据进行格式化编码
PrintData#输出查看编码后的数据格式
req = Urllib2.request (url, data #生成页面请求的完整数据
response = Urllib2. (req Span class= "com" > #发送页面请求
return. Read () #获取服务器返回的页面信息
#PUT
Import Urllib2
Request = urllib2. Request(' http://example.org ', data=' Your_put_data ')
request. ( ' Content-type ' , ' your/contenttype ' request. = lambda:< Span class= "PLN" > ' PUT '
response =< Span class= "PLN" > urllib2. (request)
#DELETE
import urllib2
request = urllib2. Request (uri)
request get_method = lambda< Span class= "pun" >: ' DELETE '
response Span class= "pun" >= urllib2. (request)
Python urllib2 for HTTP get,put,post,delete