以下是使用Python进行HTTP代理的代码示例:
```python
import requests
# 设置代理服务器
proxy = {
"http": "http://127.0.0.1:8080",
"https": "http://127.0.0.1:8080"
}
# 发送请求
response = requests.get("https://www.example.com", proxies=proxy)
# 输出响应内容
print(response.text)
```
在上面的代码中,我们使用了requests库来发送HTTP请求,并设置了代理服务器。其中,`http`和`https`分别表示HTTP和HTTPS协议的代理地址,`127.0.0.1:8080`是代理服务器的IP地址和端口号。最后,我们通过`response.text`输出了响应内容。
需要注意的是,如果代理服务器需要用户名和密码进行认证,可以在代理地址中添加用户名和密码,例如:
```python
proxy = {
"http": "http://username:[email protected]:8080",
"https": "http://username:[email protected]:8080"
}
```
其中,`username`和`password`分别是代理服务器的用户名和密码。