py-get請求實現方式
定義接口地址
定義請求數據
整理請求數據
發送數據並獲取結果
# -*-coding:utf8 -*-
import urllib
import urllib2
url ="http://reg.haibian.com/login/ajax_login"
#定義請求數據,並且對數據進行賦值
data={}
data['loginname']='[email protected]'
data['password']='111111'
#對請求數據進行編碼
data=urllib.urlencode(data)
#將數據和URL進行連接
request=url+'?'+data
#打開請求,獲取對象
requestResponse=urllib2.urlopen(request)
#讀取服務端返回的數據
ResponseStr=requestResponse.read()
#打印數據
ResponseStr=ResponStr.decode("unicode_escape")
print(ResponseStr)