url:地址换成正常即可
Get
import urllib.request
import urllib.parse
import http.client
#方法一
def get_01():
re = urllib.request.urlopen('http://pkdsdsuie.eumidsdng.com/urming_pkuie/system/getMyIndex?offset=0&pageSize=10&accessToken=')
print(re.read().decode('utf-8'))
#方法二
#有时候请求里面有汉字需要编码
def get_02():
data = {
'pageSize': 10,
'offset': 0
}
data = urllib.parse.urlencode(data)
# 转换成字节 get不需要post需要
# data = data.encode('utf-8')
re = urllib.request.urlopen('http://dsdpkdsadsduie.eudsdsming.com/urming_pkuie/system/getMyIndex?%s'%data)
print(re.read().decode('utf-8'))
if __name__ == '__main__':
get_02()
POST
import urllib.request
import urllib.parse
def post_01():
data = {
'pageSize':20,
'offset':0
}
data = urllib.parse.urlencode(data).encode('utf-8')
re = urllib.request.Request('http://pksaduie.eumindsadg.com/urdsming_pkuie/system/getMydssndex',data)
post = urllib.request.urlopen(re)
print(post.read().decode('utf-8'))
if __name__ == '__main__':
post_01()