Python and Curl submitting HTTP requests
Since OpenStack is a python implementation of WSGI's rest ful architecture, the process of learning and debugging often encounters HTTP request submissions, so you can sort through the submission methods of Python and curl commands.
1.Python article
Having a reptile experience in Python is of course quite simple, and a requests library problem is better than urllib.
Import requestsurl= "https://www.baidu.com/s" headers={' user-agent ': "mozilla/5.0 (X11; Linux x86_64) applewebkit/537.36 (khtml, like Gecko) chrome/53.0.2785.143 safari/537.36 "}post_data={' username ':" Qujun "," passwd ":" Xixi "}parameters={' WD ':" ABC "} #提交get请求P_get =request.get (url,params=parameters) #提交post请求P_post = Reuests.post (Url,headers=headers,data=post_data)
If you are involved in cookies, you can use requests. Seesion () method
2.shell in Curl
-A: Feel free to specify your own browser information as claimed by this visit-b/--cookie <name=string/file> cookie string or file read location, use option to append last cookie information to HTTP Request to go inside. -c/--cookie-jar <file> Write the cookie to this file after the operation-d/--data <data> HTTP post to transmit-f/--form <name=content> Analog HTTP form submission Data-h/--header
#curl发送get, the curl request itself belongs to get, and no parameters are found for the specified send parameter: Curl Https://www.baidu.com/s?wd=xixi#curl send Post,curl send post with two parameters-D and-F follow the results of man, the difference is that the-D effect is quite the same as in HTML Form filled out the information pressed the submit key, he will use Content-type "application/x-www-form-urlencoded", according to its use example, should be normal content post past. -F impersonate the user by pressing the Submit key and transferring the completed form. Using Content-type multi‐part/form-data, it is generally used in the case of transferring files. Curl-d "Username=qujun&passwd=xixi" Https://www.baidu.comcurl-F "[Email protected];type=text/html" example.com curl-f [email protected] https://example.com/upload.cgi
This article is from the "Danielqu" blog, make sure to keep this source http://qujunorz.blog.51cto.com/6378776/1871276
OpenStack Command line client emulates HTTP requests