Introduction of three kinds of parameter request methods for Requests
This article mainly explains the "introduction of the three parameter request methods of Requests". The content of the explanation is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn the "introduction of the three parameter request methods of Requests".
Request for URL parameters:
Import requests
''
URL Parameters request method: URL parameter
For example: request http://httpbin.org/get?first_name=hello&last_name=word in get mode
''
# params= {"first_name": "hello", "last_name": "word"}
# responds=requests.get ("http://httpbin.org/get",params=params)"
# print (responds.text)
# print (responds.url)
Form parameter request:
''
Form parameter submission, note that only the form data is updated
Content-Type: application/x-www-form-urlencoded
For example: request http://httpbin.org/post in post mode, and the added resources are params= {"first_name": "hello", "last_name": "word"}
''
Params= {"first_name": "hello", "last_name": "word"}
Headers= {"Content-Tpye": "application/x-www-form-urlencoded"}
Responds=requests.post ("http://httpbin.org/post",data=params,headers=headers)"
Print (responds.text)
Print (responds.url)
Print (responds.request)
Json parameter data request
''
Json data is submitted, and data data is updated
Content-Type: application/json
For example: request http://httpbin.org/post in post mode, and the added resources are params= {"first_name": "hello", "last_name": "word"}
''
# Python Learning Communication QQ Group: 778463939
Params= {"first_name": "hello", "last_name": "word"}
Headers= {"Content-Tpye": "application/json"}
Responds=requests.post ("http://httpbin.org/post",json=params,headers=headers)"
Print (responds.text)
Print (responds.url)
Print (responds.request)
Additional topic-- Building URL
Def build_url (URL,endpoint):
Return "/" .join ([URL,endpoint])
Print ("http://httpbin.org","post")) Thank you for your reading, the above is the content of" introduction to the three parameter request methods of Requests ". After the study of this article, I believe you have a deeper understanding of the introduction of the three parameter request methods of Requests, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!