1 #Python3 Urllib Https Request 2 import urllib.request 3 def ss(): 4 req = urllib.request.urlopen('https://baidu.com') 5 print(req.read().decode('utf-8')) 6 if __name__ == '__main__': 7 ss()
1 #Urllib Http Post/Get Method 2 3 import urllib.parse 4 import urllib.request 5 6 data = bytes(urllib.parse.urlencode({'password': 'root'}), encoding='utf8') 7 response = urllib.request.urlopen('http://127.0.0.1', data=data) 8 # print(response.read().decode('utf-8')) 9 print(response.getcode())
#Python3 Requests Http Post Method #通过headers 和 data 参数 绕过认证 401 import requests headers = { 'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/73.0.3683.103 Safari/537.36', 'Host': '192.168.1.1', 'Origin': 'http://192.168.1.1', 'Accept': '*/*', 'Referer': 'http://192.168.1.1/', 'Accept-Encoding': 'gzip, deflate', 'Accept-Language': 'zh-CN,zh;q=0.9', } data = {'password' : 'root123'} response = requests.post('http://192.168.1.1/?code=7&asyn=0&id=nO3Q%24%5Bd!sd!X77Nt',data=data, headers=headers) print (response.text) #print(response.status_code())