开发网站,少不了测试。现在的网站为了加强安全性,都启用了HTTPS协议。所谓HTTPS,也就是HTTP文本在SSL协议中传输。用curl命令行来测试HTTPS站点是个很有用的功能,写点脚本,就可以做功能测试。
假定Ubuntu系统运行着一个HTTPS站点,用CppCMS编写,Nginx配置了SSL证书,通过FastCGI和CppCMS编写的后台进程连接在一起。
第一步,安装:
apt-get install curl
我的Ubuntu是13.04, 因此安装的curl版本很新,下面的命令检查版本号和其他信息:
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
我们可以看到启用了SSL, 并且openssl版本是1.0.1c。
第二步,访问HTTP站点:
curl http://www.baidu.com
<!DOCTYPE html><!--STATUS OK--><html><head><meta http-equiv="content-type" content="text/html;charset=utf-8"><title>百度一下,你就知道<unction(){var _t=new Date().getTime();document.cookie = "WWW_ST=" + _t +";expires=" + new Date(_t + 10000).toGMTString()})}catch(e){}</script></html><!--b5d54ba904675fbf-->
返回了百度的网页内容。内容太多,裁剪了。
第三步,查看详细信息,用-v参数。
curl -v http://www.baidu.com
* About to connect() to www.baidu.com port 80 (#0)
* Trying 61.135.169.125...
* Connected to www.baidu.com (61.135.169.125) port 80 (#0)
> GET / HTTP/1.1
> User-Agent: curl/7.29.0
> Host: www.baidu.com
> Accept: */*
>
< HTTP/1.1 200 OK
< Date: Wed, 03 Jul 2013 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, 03 Jul 2013 13:55:45 GMT
< P3P: CP=" OTI DSP COR IVA OUR IND COM "
< Connection: Keep-Alive
<
<!DOCTYPE html><!--STATUS OK--><html><head><meta http-equiv="content-type" content="text/html;charset=utf-8"><title>百度一下,你就知道</title><style >html,body{height:100%}html{overflow-y:auto}#wrapper{position:relative;_position:;min-height:100%}#content{padding-bottom:100px;text-align:center}#ftCon{height:100px;position:absolute;bottom:44px;text-align:center;width:100%;margin:0 auto;z-index:0;overflow:hidden}#ftConw{width:720px;margin:0 auto}body{font:12px arial;text-align:;background:#fff}body,p,form,ul,li{margin:0;padding:0;list-style:none}body,form,#fm{position:relative}td{text-align:left}img{border:0}a{color:#00c}a:active{color:#f60}#u{color:#999;padding:4px 10px 5px 0;text-align:right}#u a{margin:0 5px}#u .reg{margin:0}#m{width:720px;margin:0 auto}#nv a,#nv b,.btn,#lk{font-size:14px}#fm{padding-left:110px;text-align:left;z-index:1}input{border:0;padding:0}#nv{height:19px;font-size:16px;margin:0 0 4px;text-alig
这样详细的信息都显示出来了。-v参数很有用,一般调试时都打开。
如果只想查看头部信息,用-i代替-v.
第四步,访问本地HTTPS站点
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">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<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表示忽略校验步骤。
我试过用--cacert选项指定server.crt文件,也就是我的nginx使用的那个文件。但是报错。所以直接忽略算了。
第五步,调用HTTPS的login API登录
curl -v --insecure -d "email=gche@yousite.com&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 (18), 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 51 bytes
< HTTP/1.1 200 OK
< Server: nginx/1.5.1
< Date: Wed, 03 Jul 2013 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 "...&..." 的参数是通过POST方法发送参数。服务端最终回复一个JSON格式的字符串,表示登录成功。并且拿到了cml_session的值,也就是cookie.
第六步,用cookie访问HTTP网页。后面的网页只需要HTTP访问,提供正确的cookie即可。
curl -v --cookie "cml_session=518b7fc5117e87bce28f2444" http://localhost/your_site/home
* About to connect() to localhost port 80 (#0)
* Trying 127.0.0.1...
* Connected to localhost (127.0.0.1) port 80 (#0)
> GET /your_site/home HTTP/1.1
> User-Agent: curl/7.29.0
> Host: localhost
> Accept: */*
> Cookie: cml_session=518b7fc5117e87bce28f2444
>
< HTTP/1.1 200 OK
< Server: nginx/1.5.1
< Date: Wed, 03 Jul 2013 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">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<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"/>
分享到:
相关推荐
这是编译好的dll(带demo),cURL比luacurl功能强大的多,项目源码及使用: https://github.com/Lua-cURL/Lua-cURLv3
测试站点相应时间 curl -o /dev/null -s -w %{time_connect}:%{time_starttransfer}:%{time_total} www.google.com 查看http_code curl -o /dev/null -s -w %{http_code} http://www.neocanable.com 网页或文件大小 ...
是curl访问https站点的时候有bug! 内存泄露可以通过linux的top命令发现,使用php函数memory_get_usage()不会发现。 经过反复调试找到解决办法,curl配置添加如下几项解决问题: 复制代码 代码如下: [CURLOPT_...
主要介绍了Shell+Curl网站状态检查脚本 抓出无法访问的站点,需要的朋友可以参考下
我们经常用curl来访问web站点,web站点目前主要分为http和https两种协议,众所周知https类型的网站都是通过ssl协议+http协议的,是目前最安全的网站协议,访问此类网站的时候,会走ssl协议,验证访问者的证书,检测...
1. Windows下使用命令行访问Web站点的工具。 2. 支持http/https 等协议 3. 下载后,解压并配置环境变量即可
Unix,Windows或Mac OS XRuby在Unix上安装ruby: yum install ruby (或sudo apt-get install ruby1.9.1 )在Mac OS X上安装ruby: curl -L https://get.rvm.io | bash -s stable --ruby 请访问以下链接,...
用户可以登录到应用程序设置/安装要求如果未安装,请确保您的计算机上已安装Python,请访问python网站并下载最新版本的python 3.6 分叉存储库,然后下载项目或将其克隆到您的计算机上使用以下命令创建虚拟环境python...
还有其他方法可以实现这一点(curl-loader、wget 等),但目标是提供一个可以在旧机器上运行的轻量级 FileMaker 解决方案,以更精细的控制启动多台服务器上的多个站点的缓存。 有关该项目的更多信息,请访问: :
php 版本必须 5.4 或更高 ,MySQL(5.1以上) PHP需开启 ...1、上传并设置权限完毕后,在浏览器访问你的站点地址 2、阅读协议后点击“同意并安装”,系统会自动检查环境及文件目录权限 3、系统会自动安装数据直至完毕
6.10 使用Nikto扫描HTTPS站点 128 6.11 使用带身份验证的Nikto 129 6.12 在特定起始点启动Nikto 130 6.13 在Nikto中使用特定的会话Cookie 131 6.14 使用WSFuzzer测试Web服务 132 6.15 理解WSFuzzer的输出结果 134 ...
如果Composer未安装在系统上或无法通过shell_exec访问,则使用位于install目录中的自包含composer.phar文件。 推荐使用cURL 推荐版本7+ 通过Composer加载的组件 jQuery 版本3.1 通过作曲家拉进来 Bootstrap 版本...
访问站点以获取最新说明。 curl https://raw.githubusercontent.com/creationix/nvm/v0.24.1/install.sh | bash 2.) 安装节点。 nvm install stable 3.) 安装所需的节点模块。 npm install nodejs -g npm ...
没有重新启动,添加新站点并立即访问它。 从任何git repo / branch / subdirectory提供服务 Git存储库自动更新以在分支上提供最新更改 简单的用户界面,用于添加和删除网站。 为每个站点提供多个主机名 将http...
本书中的秘诀所覆盖的基础知识包括了从观察客户端和服务器之间的消息到使用脚本完成登录并执行Web应用功能的多阶段测试。在本书的最后,你将能够建立精确定位到Ajax函数的测试,以及适用于常见怀疑对象(跨站式脚本...
地形使用 | | | | 安装Terraform 如果您使用的是MacOS,则可以运行下一... 对于Unix / Linux操作系统,您可以访问官方Terraform站点并下载带有软件的bin文件。 在里面 首先,您应该将此仓库克隆到本地计算机。 我提供
通过使用基于 Web 的用户界面或通过 curl、wget 等使用直接查询……人们能够检索所需的列表。 该项目的实时版本可以在上看到。 有关可能参数的完整列表,请单击。 PS 我不声称这是最好的结构化代码,也不是最...
公开其访问日志(包括引荐来源统计信息)的站点将不经意地链接回垃圾邮件发送者的站点。 这些链接将在搜索引擎抓取访问日志时被索引。 由于免费链接,这使垃圾邮件制造者受益。由于搜索引擎使用的链接计数算法,...
怎么运行的: 1)转到HTTPS网站(https:// ) 2)单击右上角的挂锁图标 3)弹出窗口将显示并显示该站点的SSL连接和PKI证书信息。 警告: 1)这使得与站点的外部连接,因此该站点需要外部可供外部访问,而且没有...