Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1485027
  • 博文数量: 129
  • 博客积分: 1449
  • 博客等级: 上尉
  • 技术积分: 3048
  • 用 户 组: 普通用户
  • 注册时间: 2012-07-24 18:36
文章分类

全部博文(129)

文章存档

2015年(3)

2014年(20)

2013年(65)

2012年(41)

分类: LINUX

2012-08-17 14:52:56


点击(此处)折叠或打开

  1. static void help(void)
  2. {
  3.   int i;
  4.   static const char * const helptext[]={
  5.     "Usage: curl [options...] ",
  6.     "Options: (H) means HTTP/HTTPS only, (F) means FTP only",
  7.     " -a/--append Append to target file when uploading (F)",
  8.     " -A/--user-agent User-Agent to send to server (H)",
  9.     " --anyauth Pick \"any\" authentication method (H)",
  10.     " -b/--cookie Cookie string or file to read cookies from (H)",
  11.     " --basic Use HTTP Basic Authentication (H)",
  12.     " -B/--use-ascii Use ASCII/text transfer",
  13.     " -c/--cookie-jar Write cookies to this file after operation (H)",
  14.     " -C/--continue-at Resumed transfer offset",
  15.     " -d/--data HTTP POST data (H)",
  16.     " --data-ascii HTTP POST ASCII data (H)",
  17.     " --data-binary HTTP POST binary data (H)",
  18.     " --negotiate Use HTTP Negotiate Authentication (H)",
  19.     " --digest Use HTTP Digest Authentication (H)",
  20.     " --disable-eprt Inhibit using EPRT or LPRT (F)",
  21.     " --disable-epsv Inhibit using EPSV (F)",
  22.     " -D/--dump-header Write the headers to this file",
  23.     " --egd-file EGD socket path for random data (SSL)",
  24.     " --tcp-nodelay Use the TCP_NODELAY option",
  25. #ifdef USE_ENVIRONMENT
  26.     " --environment Write results to environment variables (RISC OS)",
  27. #endif
  28.     " -e/--referer Referer URL (H)",
  29.     " -E/--cert Client certificate file and password (SSL)",
  30.     " --cert-type Certificate file type (DER/PEM/ENG) (SSL)",
  31.     " --key Private key file name (SSL/SSH)",
  32.     " --key-type Private key file type (DER/PEM/ENG) (SSL)",
  33.     " --pass Pass phrase for the private key (SSL/SSH)",
  34.     " --pubkey Public key file name (SSH)",
  35.     " --engine Crypto engine to use (SSL). \"--engine list\" for list",
  36.     " --cacert CA certificate to verify peer against (SSL)",
  37.     " --capath CA directory (made using c_rehash) to verify",
  38.     " peer against (SSL)",
  39.     " --hostpubmd5 Hex encoded MD5 string of the host public key. (SSH)",
  40.     " --ciphers SSL ciphers to use (SSL)",
  41.     " --compressed Request compressed response (using deflate or gzip)",
  42.     " --connect-timeout Maximum time allowed for connection",
  43.     " --create-dirs Create necessary local directory hierarchy",
  44.     " --crlf Convert LF to CRLF in upload",
  45.     " -f/--fail Fail silently (no output at all) on HTTP errors (H)",
  46.     " --ftp-account Account data to send when requested by server (F)",
  47.     " --ftp-alternative-to-user String to replace \"USER [name]\" (F)",
  48.     " --ftp-create-dirs Create the remote dirs if not present (F)",
  49.     " --ftp-method [multicwd/nocwd/singlecwd] Control CWD usage (F)",
  50.     " --ftp-pasv Use PASV/EPSV instead of PORT (F)",
  51.     " --ftp-skip-pasv-ip Skip the IP address for PASV (F)\n"
  52.     " --ftp-ssl Try SSL/TLS for ftp transfer (F)",
  53.     " --ftp-ssl-control Require SSL/TLS for ftp login, clear for transfer (F)",
  54.     " --ftp-ssl-reqd Require SSL/TLS for ftp transfer (F)",
  55.     " --ftp-ssl-ccc Send CCC after authenticating (F)",
  56.     " --ftp-ssl-ccc-mode [active/passive] Set CCC mode (F)",
  57.     " -F/--form Specify HTTP multipart POST data (H)",
  58.     " --form-string Specify HTTP multipart POST data (H)",
  59.     " -g/--globoff Disable URL sequences and ranges using {} and []",
  60.     " -G/--get Send the -d data with a HTTP GET (H)",
  61.     " -h/--help This help text",
  62.     " -H/--header Custom header to pass to server (H)",
  63.     " --ignore-content-length Ignore the HTTP Content-Length header",
  64.     " -i/--include Include protocol headers in the output (H/F)",
  65.     " -I/--head Show document info only",
  66.     " -j/--junk-session-cookies Ignore session cookies read from file (H)",
  67.     " --interface Specify network interface/address to use",
  68.     " --krb Enable kerberos with specified security level (F)",
  69.     " -k/--insecure Allow connections to SSL sites without certs (H)",
  70.     " -K/--config Specify which config file to read",
  71.     " --libcurl Dump libcurl equivalent code of this command line",
  72.     " -l/--list-only List only names of an FTP directory (F)",
  73.     " --limit-rate Limit transfer speed to this rate",
  74.     " --local-port [-num] Force use of these local port numbers\n",
  75.     " -L/--location Follow Location: hints (H)",
  76.     " --location-trusted Follow Location: and send authentication even ",
  77.     " to other hostnames (H)",
  78.     " -m/--max-time Maximum time allowed for the transfer",
  79.     " --max-redirs Maximum number of redirects allowed (H)",
  80.     " --max-filesize Maximum file size to download (H/F)",
  81.     " -M/--manual Display the full manual",
  82.     " -n/--netrc Must read .netrc for user name and password",
  83.     " --netrc-optional Use either .netrc or URL; overrides -n",
  84.     " --ntlm Use HTTP NTLM authentication (H)",
  85.     " -N/--no-buffer Disable buffering of the output stream",
  86.     " --no-sessionid Disable SSL session-ID reusing (SSL)",
  87.     " -o/--output Write output to instead of stdout",
  88.     " -O/--remote-name Write output to a file named as the remote file",
  89.     " --post301 Do not switch to GET after following a 301 redirect (H)",
  90.     " -p/--proxytunnel Operate through a HTTP proxy tunnel (using CONNECT)",
  91.     " --proxy-anyauth Pick \"any\" proxy authentication method (H)",
  92.     " --proxy-basic Use Basic authentication on the proxy (H)",
  93.     " --proxy-digest Use Digest authentication on the proxy (H)",
  94.     " --proxy-negotiate Use Negotiate authentication on the proxy (H)",
  95.     " --proxy-ntlm Use NTLM authentication on the proxy (H)",
  96.     " -P/--ftp-port
    Use PORT with address instead of PASV (F)",
  97.     " -q If used as the first parameter disables .curlrc",
  98.     " -Q/--quote Send command(s) to server before file transfer (F/SFTP)",
  99.     " -r/--range Retrieve a byte range from a HTTP/1.1 or FTP server",
  100.     " --random-file File for reading random data from (SSL)",
  101.     " --raw Pass HTTP \"raw\", without any transfer decoding (H)",
  102.     " -R/--remote-time Set the remote file's time on the local output",
  103.     " --retry Retry request times if transient problems occur",
  104.     " --retry-delay When retrying, wait this many seconds between each",
  105.     " --retry-max-time Retry only within this period",
  106.     " -s/--silent Silent mode. Don't output anything",
  107.     " -S/--show-error Show error. With -s, make curl show errors when they occur",
  108.     " --socks4 Use SOCKS4 proxy on given host + port",
  109.     " --socks5 Use SOCKS5 proxy on given host + port",
  110.     " --stderr Where to redirect stderr. - means stdout",
  111.     " -t/--telnet-option Set telnet option",
  112.     " --trace Write a debug trace to the given file",
  113.     " --trace-ascii Like --trace but without the hex output",
  114.     " --trace-time Add time stamps to trace/verbose output",
  115.     " -T/--upload-file Transfer to remote site",
  116.     " --url Set URL to work with",
  117.     " -u/--user Set server user and password",
  118.     " -U/--proxy-user Set proxy user and password",
  119.     " -v/--verbose Make the operation more talkative",
  120.     " -V/--version Show version number and quit",
  121. #ifdef MSDOS
  122.     " --wdebug Turn on Watt-32 debugging under DJGPP",
  123. #endif
  124.     " -w/--write-out [format] What to output after completion",
  125.     " -x/--proxy Use HTTP proxy on given port",
  126.     " -X/--request Specify request command to use",
  127.     " -y/--speed-time Time needed to trig speed-limit abort. Defaults to 30",
  128.     " -Y/--speed-limit Stop transfer if below speed-limit for 'speed-time' secs",
  129.     " -z/--time-cond ,
  130.     " -0/--http1.0 Use HTTP 1.0 (H)",
  131.     " -1/--tlsv1 Use TLSv1 (SSL)",
  132.     " -2/--sslv2 Use SSLv2 (SSL)",
  133.     " -3/--sslv3 Use SSLv3 (SSL)",
  134.     " -4/--ipv4 Resolve name to IPv4 address",
  135.     " -6/--ipv6 Resolve name to IPv6 address",
  136.     " -#/--progress-bar Display transfer progress as a progress bar",
  137.     NULL
  138.   };
  139.   for(i=0; helptext[i]; i++) {
  140.     puts(helptext[i]);
  141. #ifdef NETWARE
  142.     if (i && ((i % 23) == 0))
  143.       pressanykey();
  144. #endif
  145.   }
  146. }

点击(此处)折叠或打开

  1. -a/--append 上传文件时,附加到目标文件
  2.   -A/--user-agent <string> 设置用户代理发送给服务器
  3.   - anyauth 可以使用“任何”身份验证方法
  4.   -b/--cookie <name=string/file> cookie字符串或文件读取位置
  5.   - basic 使用HTTP基本验证
  6.   -B/--use-ascii 使用ASCII /文本传输
  7.   -c/--cookie-jar <file> 操作结束后把cookie写入到这个文件中
  8.   -C/--continue-at <offset> 断点续转
  9.   -d/--data <data> HTTP POST方式传送数据
  10.   --data-ascii <data> 以ascii的方式post数据
  11.   --data-binary <data> 以二进制的方式post数据
  12.   --negotiate 使用HTTP身份验证
  13.   --digest 使用数字身份验证
  14.   --disable-eprt 禁止使用EPRT或LPRT
  15.   --disable-epsv 禁止使用EPSV
  16.   -D/--dump-header <file> 把header信息写入到该文件中
  17.   --egd-file <file> 为随机数据(SSL)设置EGD socket路径
  18.   --tcp-nodelay 使用TCP_NODELAY选项
  19.   -e/--referer 来源网址
  20.   -E/--cert <cert[:passwd]> 客户端证书文件和密码 (SSL)
  21.   --cert-type <type> 证书文件类型 (DER/PEM/ENG) (SSL)
  22.   --key <key> 私钥文件名 (SSL)
  23.   --key-type <type> 私钥文件类型 (DER/PEM/ENG) (SSL)
  24.   --pass <pass> 私钥密码 (SSL)
  25.   --engine <eng> 加密引擎使用 (SSL). "--engine list" for list
  26.   --cacert <file> CA证书 (SSL)
  27.   --capath <directory> CA目录 (made using c_rehash) to verify peer against (SSL)
  28.   --ciphers <list> SSL密码
  29.   --compressed 要求返回是压缩的形势 (using deflate or gzip)
  30.   --connect-timeout <seconds> 设置最大请求时间
  31.   --create-dirs 建立本地目录的目录层次结构
  32.   --crlf 上传是把LF转变成CRLF
  33.   -f/--fail 连接失败时不显示http错误
  34.   --ftp-create-dirs 如果远程目录不存在,创建远程目录
  35.   --ftp-method [multicwd/nocwd/singlecwd] 控制CWD的使用
  36.   --ftp-pasv 使用 PASV/EPSV 代替端口
  37.   --ftp-skip-pasv-ip 使用PASV的时候,忽略该IP地址
  38.   --ftp-ssl 尝试用 SSL/TLS 来进行ftp数据传输
  39.   --ftp-ssl-reqd 要求用 SSL/TLS 来进行ftp数据传输
  40.   -F/--form <name=content> 模拟http表单提交数据
  41.   -form-string <name=string> 模拟http表单提交数据
  42.   -g/--globoff 禁用网址序列和范围使用{}[]
  43.   -G/--get 以get的方式来发送数据
  44.   -h/--help 帮助
  45.   -H/--header <line>自定义头信息传递给服务器
  46.   --ignore-content-length 忽略的HTTP头信息的长度
  47.   -i/--include 输出时包括protocol头信息
  48.   -I/--head 只显示文档信息
  49.   从文件中读取-j/--junk-session-cookies忽略会话Cookie
  50.   - 界面<interface>指定网络接口/地址使用
  51.   - krb4 <级别>启用与指定的安全级别krb4
  52.   -j/--junk-session-cookies 读取文件进忽略session cookie
  53.   --interface <interface> 使用指定网络接口/地址
  54.   --krb4 <level> 使用指定安全级别的krb4
  55.   -k/--insecure 允许不使用证书到SSL站点
  56.   -K/--config 指定的配置文件读取
  57.   -l/--list-only 列出ftp目录下的文件名称
  58.   --limit-rate <rate> 设置传输速度
  59.   --local-port<NUM> 强制使用本地端口号
  60.   -m/--max-time <seconds> 设置最大传输时间
  61.   --max-redirs <num> 设置最大读取的目录数
  62.   --max-filesize <bytes> 设置最大下载的文件总量
  63.   -M/--manual 显示全手动
  64.   -n/--netrc 从netrc文件中读取用户名和密码
  65.   --netrc-optional 使用 .netrc 或者 URL来覆盖-n
  66.   --ntlm 使用 HTTP NTLM 身份验证
  67.   -N/--no-buffer 禁用缓冲输出
  68.   -o/--output 把输出写到该文件中
  69.   -O/--remote-name 把输出写到该文件中,保留远程文件的文件名
  70.   -p/--proxytunnel 使用HTTP代理
  71.   --proxy-anyauth 选择任一代理身份验证方法
  72.   --proxy-basic 在代理上使用基本身份验证
  73.   --proxy-digest 在代理上使用数字身份验证
  74.   --proxy-ntlm 在代理上使用ntlm身份验证
  75.   -P/--ftp-port <address> 使用端口地址,而不是使用PASV
  76.   -Q/--quote <cmd>文件传输前,发送命令到服务器
  77.   -r/--range <range>检索来自HTTP/1.1或FTP服务器字节范围
  78.   --range-file 读取(SSL)的随机文件
  79.   -R/--remote-time 在本地生成文件时,保留远程文件时间
  80.   --retry <num> 传输出现问题时,重试的次数
  81.   --retry-delay <seconds> 传输出现问题时,设置重试间隔时间
  82.   --retry-max-time <seconds> 传输出现问题时,设置最大重试时间
  83.   -s/--silent静音模式。不输出任何东西
  84.   -S/--show-error 显示错误
  85.   --socks4 <host[:port]> 用socks4代理给定主机和端口
  86.   --socks5 <host[:port]> 用socks5代理给定主机和端口
  87.   --stderr <file>
  88. -t/--telnet-option <OPT=val> Telnet选项设置
  89.   --trace <file> 对指定文件进行debug
  90.   --trace-ascii <file> Like --跟踪但没有hex输出
  91.   --trace-time 跟踪/详细输出时,添加时间戳
  92.   -T/--upload-file <file> 上传文件
  93.   --url <URL> Spet URL to work with
  94.   -u/--user <user[:password]>设置服务器的用户和密码
  95.   -U/--proxy-user <user[:password]>设置代理用户名和密码
  96.   -v/--verbose
  97.   -V/--version 显示版本信息
  98.   -w/--write-out [format]什么输出完成后
  99.   -x/--proxy <host[:port]>在给定的端口上使用HTTP代理
  100.   -X/--request <command>指定什么命令
  101.   -y/--speed-time 放弃限速所要的时间。默认为30
  102.   -Y/--speed-limit 停止传输速度的限制,速度时间'
  103.   -z/--time-cond 传送时间设置
  104.   -0/--http1.0 使用HTTP 1.0
  105.   -1/--tlsv1 使用TLSv1(SSL)
  106.   -2/--sslv2 使用SSLv2的(SSL)
  107.   -3/--sslv3 使用的SSLv3(SSL)
  108.   --3p-quote like -Q for the source URL for 3rd party transfer
  109.   --3p-url 使用url,进行第三方传送
  110.   --3p-user 使用用户名和密码,进行第三方传送
  111.   -4/--ipv4 使用IP4
  112.   -6/--ipv6 使用IP6
  113.   -#/--progress-bar 用进度条显示当前的传送状态
  114.   -a/--append 上传文件时,附加到目标文件
  115.   -A/--user-agent <string> 设置用户代理发送给服务器
  116.   - anyauth 可以使用“任何”身份验证方法
  117.   -b/--cookie <name=string/file> cookie字符串或文件读取位置
  118.   - basic 使用HTTP基本验证
  119.   -B/--use-ascii 使用ASCII /文本传输
  120.   -c/--cookie-jar <file> 操作结束后把cookie写入到这个文件中
  121.   -C/--continue-at <offset> 断点续转
  122.   -d/--data <data> HTTP POST方式传送数据
  123.   --data-ascii <data> 以ascii的方式post数据
  124.   --data-binary <data> 以二进制的方式post数据
  125.   --negotiate 使用HTTP身份验证
  126.   --digest 使用数字身份验证
  127.   --disable-eprt 禁止使用EPRT或LPRT
  128.   --disable-epsv 禁止使用EPSV
  129.   -D/--dump-header <file> 把header信息写入到该文件中
  130.   --egd-file <file> 为随机数据(SSL)设置EGD socket路径
  131.   --tcp-nodelay 使用TCP_NODELAY选项
  132.   -e/--referer 来源网址
  133.   -E/--cert <cert[:passwd]> 客户端证书文件和密码 (SSL)
  134.   --cert-type <type> 证书文件类型 (DER/PEM/ENG) (SSL)
  135.   --key <key> 私钥文件名 (SSL)
  136.   --key-type <type> 私钥文件类型 (DER/PEM/ENG) (SSL)
  137.   --pass <pass> 私钥密码 (SSL)
  138.   --engine <eng> 加密引擎使用 (SSL). "--engine list" for list
  139.   --cacert <file> CA证书 (SSL)
  140.   --capath <directory> CA目录 (made using c_rehash) to verify peer against (SSL)
  141.   --ciphers <list> SSL密码
  142.   --compressed 要求返回是压缩的形势 (using deflate or gzip)
  143.   --connect-timeout <seconds> 设置最大请求时间
  144.   --create-dirs 建立本地目录的目录层次结构
  145.   --crlf 上传是把LF转变成CRLF
  146.   -f/--fail 连接失败时不显示http错误
  147.   --ftp-create-dirs 如果远程目录不存在,创建远程目录
  148.   --ftp-method [multicwd/nocwd/singlecwd] 控制CWD的使用
  149.   --ftp-pasv 使用 PASV/EPSV 代替端口
  150.   --ftp-skip-pasv-ip 使用PASV的时候,忽略该IP地址
  151.   --ftp-ssl 尝试用 SSL/TLS 来进行ftp数据传输
  152.   --ftp-ssl-reqd 要求用 SSL/TLS 来进行ftp数据传输
  153.   -F/--form <name=content> 模拟http表单提交数据
  154.   -form-string <name=string> 模拟http表单提交数据
  155.   -g/--globoff 禁用网址序列和范围使用{}[]
  156.   -G/--get 以get的方式来发送数据
  157.   -h/--help 帮助
  158.   -H/--header <line>自定义头信息传递给服务器
  159.   --ignore-content-length 忽略的HTTP头信息的长度
  160.   -i/--include 输出时包括protocol头信息
  161.   -I/--head 只显示文档信息
  162.   从文件中读取-j/--junk-session-cookies忽略会话Cookie
  163.   - 界面<interface>指定网络接口/地址使用
  164.   - krb4 <级别>启用与指定的安全级别krb4
  165.   -j/--junk-session-cookies 读取文件进忽略session cookie
  166.   --interface <interface> 使用指定网络接口/地址
  167.   --krb4 <level> 使用指定安全级别的krb4
  168.   -k/--insecure 允许不使用证书到SSL站点
  169.   -K/--config 指定的配置文件读取
  170.   -l/--list-only 列出ftp目录下的文件名称
  171.   --limit-rate <rate> 设置传输速度
  172.   --local-port<NUM> 强制使用本地端口号
  173.   -m/--max-time <seconds> 设置最大传输时间
  174.   --max-redirs <num> 设置最大读取的目录数
  175.   --max-filesize <bytes> 设置最大下载的文件总量


  176. -M/--manual 显示全手动

  177.   -n/--netrc 从netrc文件中读取用户名和密码

  178.   --netrc-optional 使用 .netrc 或者 URL来覆盖-n

  179.   --ntlm 使用 HTTP NTLM 身份验证

  180.   -N/--no-buffer 禁用缓冲输出

  181.   -o/--output 把输出写到该文件中

  182.   -O/--remote-name 把输出写到该文件中,保留远程文件的文件名

  183.   -p/--proxytunnel 使用HTTP代理

  184.   --proxy-anyauth 选择任一代理身份验证方法

  185.   --proxy-basic 在代理上使用基本身份验证

  186.   --proxy-digest 在代理上使用数字身份验证

  187.   --proxy-ntlm 在代理上使用ntlm身份验证

  188.   -P/--ftp-port <address> 使用端口地址,而不是使用PASV

  189.   -Q/--quote <cmd>文件传输前,发送命令到服务器

  190.   -r/--range <range>检索来自HTTP/1.1或FTP服务器字节范围

  191.   --range-file 读取(SSL)的随机文件

  192.   -R/--remote-time 在本地生成文件时,保留远程文件时间

  193.   --retry <num> 传输出现问题时,重试的次数

  194.   --retry-delay <seconds> 传输出现问题时,设置重试间隔时间

  195.   --retry-max-time <seconds> 传输出现问题时,设置最大重试时间

  196.   -s/--silent静音模式。不输出任何东西

  197.   -S/--show-error 显示错误

  198.   --socks4 <host[:port]> 用socks4代理给定主机和端口

  199.   --socks5 <host[:port]> 用socks5代理给定主机和端口

  200.   --stderr <file>

  201.   -t/--telnet-option <OPT=val> Telnet选项设置

  202.   --trace <file> 对指定文件进行debug

  203.   --trace-ascii <file> Like --跟踪但没有hex输出

  204.   --trace-time 跟踪/详细输出时,添加时间戳

  205.   -T/--upload-file <file> 上传文件

  206.   --url <URL> Spet URL to work with

  207.   -u/--user <user[:password]>设置服务器的用户和密码

  208.   -U/--proxy-user <user[:password]>设置代理用户名和密码

  209.   -v/--verbose

  210.   -V/--version 显示版本信息

  211.   -w/--write-out [format]什么输出完成后

  212.   -x/--proxy <host[:port]>在给定的端口上使用HTTP代理

  213.   -X/--request <command>指定什么命令

  214.   -y/--speed-time 放弃限速所要的时间。默认为30

  215.   -Y/--speed-limit 停止传输速度的限制,速度时间'

  216.   -z/--time-cond 传送时间设置

  217.   -0/--http1.0 使用HTTP 1.0

  218.   -1/--tlsv1 使用TLSv1(SSL)

  219.   -2/--sslv2 使用SSLv2的(SSL)

  220.   -3/--sslv3 使用的SSLv3(SSL)

  221.   --3p-quote like -Q for the source URL for 3rd party transfer

  222.   --3p-url 使用url,进行第三方传送

  223.   --3p-user 使用用户名和密码,进行第三方传送

  224.   -4/--ipv4 使用IP4

  225.   -6/--ipv6 使用IP6

  226.   -#/--progress-bar 用进度条显示当前的传送状态
------------------------------------
//源码下载和安装
wget http://curl.haxx.se/download/curl-7.17.1.tar.gz
tar zxvf curl-7.17.1.tar.gz
cd curl-7.17.1
./configure --prefix=/usr/local/curl
make
make install
---------------------------------------- 

http提交一个表单,比较常用的是POST模式和GET模式, GET模式什么option都不用,只需要把变量写在url里面就可以了
比如:
curl
而POST模式的option则是 -d
curl -d "user=nickwolfe&password=12345"
就相当于向这个站点发出一次登陆申请~~~~~

一点需要注意的是,POST模式下的文件上的文件上传,比如
这样一个HTTP表单,我们要用curl进行模拟,就该是这样的语法:
curl -F upload=@localfile -F nick=go ~zzh/up_file.cgi

用curl命令,post提交带空格的数据
今天偶然遇到一个情况,我想用curl登入一个网页,无意间发现要post的数据里带空格。比如用户名为"abcdef",密码为"abc def",其中有一个空格,按照我以前的方式提交:
curl -D cookie -d "username=abcdef&password=abc def" 提示登入失败。

于是查看curl手册man curl。找到:
d/--data (HTTP) Sends the speci?ed data in a POST request to the HTTP server, in a way that can emulate as if a user has ?lled in a HTML form and pressed the
submit button. Note that the data is sent exactly as speci?ed with no extra processing (with all newlines cut off). The data is expected to be "url-encoded".
This will cause curl to pass the data to the server using the content-type application/x-www-form-urlencoded. Compare to -F/--form. If this option is used
more than once on the same command line, the data pieces speci?ed will be merged together with a separating &-letter. Thus, using ’-d name=daniel -d
skill=lousy’ would generate a post chunk that looks like ’name=daniel&skill=lousy’.
于是改用:
curl -D cookie -d "username=abcdef" -d "password=abc efg" 这样就能成功登入了。

监控网页的响应时间
curl -o /dev/null -s -w "time_connect: %{time_connect}\ntime_starttransfer: %{time_starttransfer}\ntime_total: %{time_total}\n" ""
返回:
time_connect: 1.615
time_starttransfer: 2.376
time_total: 3.615

监控站点可用性
curl -o /dev/null -s -w %{http_code} ""
返回: 200

阅读(1706) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~