Use Curl to access the HTTPS site and log in (the results returned by HTTP are particularly clear)

Source: Internet
Author: User
Tags openssl version ssl certificate self signed certificate ssl connection

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?
    1. 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?
    1. Curl-v
    2. 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
    3. Protocols:dict file ftp FTPs Gopher HTTP HTTPS IMAP imaps LDAP ldaps POP3 pop3s rtmp rtsp smtp Smtps telnet tftp
    4. 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?
    1. Curl http://www.baidu.com
    2. <! DOCTYPE html><!--STATUS ok-->Copyprint?
      1. Curl-v http://www.baidu.com
      2. * About-to-connect () to www.baidu.com Port (#0)
      3. * Trying 61.135.169.125 ...
      4. * Connected to Www.baidu.com (61.135.169.125) port (#0)
      5. > get/http/1.1
      6. > user-agent:curl/7.29.0
      7. > Host:www.baidu.com
      8. > Accept: */*
      9. >
      10. < http/1.1 OK
      11. < date:wed, 13:55:45 GMT
      12. < server:bws/1.0
      13. < content-length:10437
      14. < Content-type:text/html;charset=utf-8
      15. < Cache-control:private
      16. < set-cookie:bdsvrtm=24; path=/
      17. < set-cookie:h_ps_pssid=2757_1457_2704_2726_1788_2249_2702; path=/; Domain=.baidu.com
      18. < set-cookie:baiduid=5e81f8e70c5de6edb5c24088e3e56359:fg=1; expires=wed, 03-jul-43 13:55:45 GMT; path=/; Domain=.baidu.com
      19. < expires:wed, 13:55:45 GMT
      20. < p3p:cp= "OTI DSP COR IVA our IND COM"
      21. < connection:keep-alive
      22. <
      23. <! 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?
        1. Curl--insecure Https://localhost/your_site/login_page
        2. <! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">
        3. <meta http-equiv= "Content-type" content= "text/html; Charset=utf-8 ">
        4. <meta http-equiv= "Pragma" content= "No-cache" >
        5. <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?
      1. Curl-v--insecure-d "[Email protected]&pwd=123456&language=en" Https://localhost/your_site/login
      2. * About-to-connect () to localhost port 443 (#0)
      3. * Trying 127.0.0.1 ...
      4. * Connected to localhost (127.0.0.1) port 443 (#0)
      5. * Successfully set certificate Verify locations:
      6. * Cafile:none
      7. Capath:/etc/ssl/certs
      8. * SSLv3, TLS handshake, Client hello (1):
      9. * SSLv3, TLS handshake, Server Hello (2):
      10. * SSLv3, TLS handshake, CERT (11):
      11. * SSLv3, TLS handshake, Server key Exchange (12):
      12. * SSLv3, TLS handshake, Server finished (14):
      13. * SSLv3, TLS handshake, Client key Exchange (16):
      14. * SSLv3, TLS change cipher, Client hello (1):
      15. * SSLv3, TLS handshake, finished (20):
      16. * SSLv3, TLS change cipher, Client hello (1):
      17. * SSLv3, TLS handshake, finished (20):
      18. * SSL Connection using Ecdhe-rsa-aes256-sha
      19. * Server Certificate:
      20. * SUBJECT:C=AU; St=some-state; O=internet widgits Pty LTD
      21. * Start date:2013-06-02 07:24:53 GMT
      22. * Expire date:2014-06-02 07:24:53 GMT
      23. * ISSUER:C=AU; St=some-state; O=internet widgits Pty LTD
      24. * SSL Certificate Verify result:self signed certificate, continuing anyway.
      25. > Post/your_site/login http/1.1
      26. > user-agent:curl/7.29.0
      27. > Host:localhost
      28. > Accept: */*
      29. > content-length:51
      30. > content-type:application/x-www-form-urlencoded
      31. >
      32. * Upload completely sent off:51 out of Wuyi bytes
      33. < http/1.1 OK
      34. < server:nginx/1.5.1
      35. < date:wed, 14:02:38 GMT
      36. < content-type:text/html; Charset=utf-8
      37. < transfer-encoding:chunked
      38. < connection:keep-alive
      39. < x-powered-by:cppcms/1.0.3
      40. < set-cookie:cml_session=518b7fc5117e87bce28f2444; max-age=36000; path=/; Version=1
      41. <
      42. * Connection #0 to host localhost-left intact
      43. {"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?
      1. Curl-v--cookie "cml_session=518b7fc5117e87bce28f2444" Http://localhost/your_site/home
      2. * About to connect () to localhost port (#0)
      3. * Trying 127.0.0.1 ...
      4. * Connected to localhost (127.0.0.1) port (#0)
      5. > Get/your_site/home http/1.1
      6. > user-agent:curl/7.29.0
      7. > Host:localhost
      8. > Accept: */*
      9. > cookie:cml_session=518b7fc5117e87bce28f2444
      10. >
      11. < http/1.1 OK
      12. < server:nginx/1.5.1
      13. < date:wed, 14:06:43 GMT
      14. < content-type:text/html; Charset=utf-8
      15. < transfer-encoding:chunked
      16. < connection:keep-alive
      17. < x-powered-by:cppcms/1.0.3
      18. <
      19. <! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">
      20. <meta http-equiv= "Content-type" content= "text/html; Charset=utf-8 ">
      21. <meta http-equiv= "Pragma" content= "No-cache" >
      22. <meta http-equiv= "Cache-control" content= "No-cache" >
      23. <meta http-equiv= "Expires" content= "0" >
      24. <TITLE>CML cloud</title>
      25. <link type= "Text/css" href= ". /style/reset.css "rel=" stylesheet "/>
      26. <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)

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.