Python Http request

If we want to transfer messages between the client and the server, we can use the HTTP protocol to request
HTTP protocol requests are mainly divided into 6 types (GET and POST are more commonly used)

1) GET requests
pass information through the URL, which can be directly in the URL Write the information to be transmitted, or it can be transmitted by the form (the information in the form will be automatically converted into the data in the URL address, and passed through the URL address) Remarks: The resources have been obtained and added
to the message body in the response
2 ) POST request
can submit data to the server, which is a relatively safe way of data transmission. For example, when logging in,  POST  request is often used to send data
3) PUT request
Request the server to store a resource, usually need to specify the storage location
4) DELETE request
Request the server to delete a resource
5) HEAD
request to obtain the corresponding HTTP header information
6) OPTIONS request
to obtain the request type supported by the current URL
Response Code

status code: 200 OK
indicates that the request has been successful. By default, a successful request will be Cache


#! -*- encoding:utf-8 -*-

import requests

# The target page to be accessed
targetUrl = " http://ip.hahado.cn/ip "

# Proxy server
proxyHost = "http://ip.hahado.cn"
proxyPort = "39010"

# 代理隧道验证信息
proxyUser = "username"
proxyPass = "password"

proxyMeta = "http://%(user)s:%(pass)s@%(host)s:%(port)s" % {
"host" : proxyHost,
"port" : proxyPort,
"user" : proxyUser,
"pass" : proxyPass,
}

proxies = {
"http" : proxyMeta,
"https" : proxyMeta,
}

resp = requests.get(targetUrl, proxies=proxies)

print resp.status_code
print resp.text

おすすめ

転載: blog.csdn.net/weixin_73725158/article/details/130146470