Develop web sites, without testing. The web site now has the HTTPS protocol enabled to enhance security. The so-called HTTPS, which is HTTP text, is transmitted in the SSL protocol. Using the Curl command line to test the HTTPS site is a useful feature, writing a script, you can do functional testing.
Assume that the Ubuntu system is running an HTTPS site, written in Cppcms, Nginx configured SSL certificate, through the fastcgi and cppcms written by the background process connected together.
First step, install:
[Plain]View PlainCopyprint?
- Apt-get Install Curl
My Ubuntu is 13.04, so the version of Curl installed is very new, the following command checks the version number and other information:
[Plain]View PlainCopyprint?
- Curl-v
- Curl 7.29.0 (X86_64-PC-LINUX-GNU) libcurl/7.29.0 openssl/1.0.1c zlib/1.2.7 libidn/1.25 librtmp/2.3
- Protocols:dict file ftp FTPs Gopher HTTP HTTPS IMAP imaps LDAP ldaps POP3 pop3s rtmp rtsp smtp Smtps telnet tftp
- Features:gss-negotiate IDN IPv6 largefile NTLM ntlm_wb SSL libz TLS-SRP
We can see that SSL is enabled and the OpenSSL version is 1.0.1c.
The second step is to access the HTTP site:
[Plain]View PlainCopyprint?
- Curl http://www.baidu.com
- <! DOCTYPE html><!--STATUS ok-->Copyprint?
- Curl-v http://www.baidu.com
- * About-to-connect () to www.baidu.com Port (#0)
- * Trying 61.135.169.125 ...
- * Connected to Www.baidu.com (61.135.169.125) port (#0)
- > get/http/1.1
- > user-agent:curl/7.29.0
- > Host:www.baidu.com
- > Accept: */*
- >
- < http/1.1 OK
- < date:wed, 13:55:45 GMT
- < server:bws/1.0
- < content-length:10437
- < Content-type:text/html;charset=utf-8
- < Cache-control:private
- < set-cookie:bdsvrtm=24; path=/
- < set-cookie:h_ps_pssid=2757_1457_2704_2726_1788_2249_2702; path=/; Domain=.baidu.com
- < set-cookie:baiduid=5e81f8e70c5de6edb5c24088e3e56359:fg=1; expires=wed, 03-jul-43 13:55:45 GMT; path=/; Domain=.baidu.com
- < expires:wed, 13:55:45 GMT
- < p3p:cp= "OTI DSP COR IVA our IND COM"
- < connection:keep-alive
- <
- <! doctype html><!--status ok-->
Such detailed information is displayed. The-v parameter is useful, and is usually turned on when debugging.
If you want to see only the header information, use-I instead of-V.
Fourth step, visit the local HTTPS site
[Plain]View PlainCopyprint?
- Curl--insecure Https://localhost/your_site/login_page
- <! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">
-
-
- <meta http-equiv= "Content-type" content= "text/html; Charset=utf-8 ">
- <meta http-equiv= "Pragma" content= "No-cache" >
- <meta http-equiv= "Cache-control" content= "No-cache" >
---insecure indicates that the validation step is ignored.
I tried to specify the Server.crt file with the--cacert option, which is the file that my Nginx uses. But the error. So just ignore it and forget it.
Fifth step, call the HTTPS login API
[Plain]View PlainCopyprint?
- Curl-v--insecure-d "[Email protected]&pwd=123456&language=en" Https://localhost/your_site/login
- * About-to-connect () to localhost port 443 (#0)
- * Trying 127.0.0.1 ...
- * Connected to localhost (127.0.0.1) port 443 (#0)
- * Successfully set certificate Verify locations:
- * Cafile:none
- Capath:/etc/ssl/certs
- * SSLv3, TLS handshake, Client hello (1):
- * SSLv3, TLS handshake, Server Hello (2):
- * SSLv3, TLS handshake, CERT (11):
- * SSLv3, TLS handshake, Server key Exchange (12):
- * SSLv3, TLS handshake, Server finished (14):
- * SSLv3, TLS handshake, Client key Exchange (16):
- * SSLv3, TLS change cipher, Client hello (1):
- * SSLv3, TLS handshake, finished (20):
- * SSLv3, TLS change cipher, Client hello (1):
- * SSLv3, TLS handshake, finished (20):
- * SSL Connection using Ecdhe-rsa-aes256-sha
- * Server Certificate:
- * SUBJECT:C=AU; St=some-state; O=internet widgits Pty LTD
- * Start date:2013-06-02 07:24:53 GMT
- * Expire date:2014-06-02 07:24:53 GMT
- * ISSUER:C=AU; St=some-state; O=internet widgits Pty LTD
- * SSL Certificate Verify result:self signed certificate, continuing anyway.
- > Post/your_site/login http/1.1
- > user-agent:curl/7.29.0
- > Host:localhost
- > Accept: */*
- > content-length:51
- > content-type:application/x-www-form-urlencoded
- >
- * Upload completely sent off:51 out of Wuyi bytes
- < http/1.1 OK
- < server:nginx/1.5.1
- < date:wed, 14:02:38 GMT
- < content-type:text/html; Charset=utf-8
- < transfer-encoding:chunked
- < connection:keep-alive
- < x-powered-by:cppcms/1.0.3
- < set-cookie:cml_session=518b7fc5117e87bce28f2444; max-age=36000; path=/; Version=1
- <
- * Connection #0 to host localhost-left intact
- {"Message": "Login succeeded!", "status": 0, "value": ""}
-D "... & ..." Parameters are sent via the Post method. The server eventually replies to a JSON-formatted string that indicates a successful login. And get the Cml_session value, which is the cookie.
The sixth step is to use cookies to access HTTP Web pages. The following pages only require HTTP access, providing the correct cookie.
[Plain]View PlainCopyprint?
- Curl-v--cookie "cml_session=518b7fc5117e87bce28f2444" Http://localhost/your_site/home
- * About to connect () to localhost port (#0)
- * Trying 127.0.0.1 ...
- * Connected to localhost (127.0.0.1) port (#0)
- > Get/your_site/home http/1.1
- > user-agent:curl/7.29.0
- > Host:localhost
- > Accept: */*
- > cookie:cml_session=518b7fc5117e87bce28f2444
- >
- < http/1.1 OK
- < server:nginx/1.5.1
- < date:wed, 14:06:43 GMT
- < content-type:text/html; Charset=utf-8
- < transfer-encoding:chunked
- < connection:keep-alive
- < x-powered-by:cppcms/1.0.3
- <
- <! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">
- <meta http-equiv= "Content-type" content= "text/html; Charset=utf-8 ">
- <meta http-equiv= "Pragma" content= "No-cache" >
- <meta http-equiv= "Cache-control" content= "No-cache" >
- <meta http-equiv= "Expires" content= "0" >
- <TITLE>CML cloud</title>
- <link type= "Text/css" href= ". /style/reset.css "rel=" stylesheet "/>
- <link type= "Text/css" href= ". /style/style.css "rel=" stylesheet "/>
http://blog.csdn.net/csfreebird/article/details/9237925
Use Curl to access the HTTPS site and log in (the results returned by HTTP are particularly clear)