温馨提示:
1. httpclient的代码样例同时支持访问http和https网页
2. 此样例为终端IP授权
参考样例
import http.client #代理服务器的地址和端口 proxy_host="168.168.168.168" proxy_port=12345 #目标服务器的地址 target_host="http://example.com" #创建连接对象 conn=http.client.HTTPSConnection(proxy_host,proxy_port) #设置代理信息 conn.set_tunnel(target_host) #发送请求 conn.request("GET","/testproxy") #获取响应 response=conn.getresponse() #打印响应状态和内容 print(response.status,response.reason) print(response.read().decode('utf-8')) #关闭连接 conn.close()