1. 程式人生 > >Python解決web基礎$_POST 30

Python解決web基礎$_POST 30

#POST請求的資料儲存在表單中dict

#利用字典dict = {'what':'flag'}可以達到這一要求


from urllib import request,parse

url = "http://123.206.87.240:8002/post/"

headrs = {

'User-Agent':"Mozilla/4.0 (compatible; MSIE 5.5;Windows NT)",

'Host':'httpbin.org'

}

dict = {'what':'flag'}

data = bytes(parse.urlencode(dict),encoding='utf8')

req = request.Request(url=url,data=data,headers=headrs,method='POST')

response = request.urlopen(req)

print(response.read().decode('utf-8'))

image

image