OpenStack Command line client emulates HTTP requests

Source: Internet
Author: User
Tags html form http post

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
    • Common parameters

-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 
    • Using the example

#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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.