Python模拟HTTP Basic Authorization认证请求

需要在HTTP请求头部添加Authorization字段,用户名密码中间用冒号隔开然后进行base64转码
#!/bin/python3
#-*- coding: utf-8 -*-

def p(x): print(x)
def pt(x): print(x, type(x))

import base64
import urllib
import http.client
 
headers = {"Host":"10.10.10.1",
           "Authorization": "Basic "+base64.b64encode(b'admin:admin').decode()
           }
conn = http.client.HTTPConnection("10.10.10.1") 
conn.request(method="GET",url="/test.php", headers=headers) 
response = conn.getresponse() 

p(headers)
p(response.read().strip())


发表于:2017-10-18 15:02:25

原文链接(转载请保留): http://www.multisilicon.com/blog/a23316951.html

友情链接: MICROIC
首页