用curl命令,post提交带空格的数据

简介: 今天偶然遇到一个情况,我想用curl登入一个网页,无意间发现要post的数据里带空格。比如用户名为"abcdef",密码为"abc def",其中有一个空格,按照我以前的方式提交: curl -D cookie -d "username=abcdef&password=abc def" http://login.xxx.com/ 提示登入失败。 于是查看curl手册man cur

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

curl -D cookie -d "username=abcdef&password=abc def" http://login.xxx.com/

提示登入失败。

于是查看curl手册man curl。找到:

d/--data 
         (HTTP) Sends the specified data in a POST request to the HTTP server, in a way that can emulate
         as if a user has filled in a HTML form and pressed the submit button. Note that the data is sent
         exactly as specified 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 applica-
         tion/x-www-form-urlencoded. Compare to -F/--form. If this option is used more than once on the
         same command line, the data pieces specified 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" http://login.xxx.com/

这样就能成功登入了。


版权声明

本人的所有原创文章皆保留版权,请尊重原创作品。
转载必须包含本声明,保持本文完整,并以超链接形式注明原始作者“redraiment”和主站点上的本文原始地址。

联系方式

我的邮箱,欢迎来信(redraiment@gmail.com
我的Blogger(子清行
我的Google Sites(子清行
我的CSDN博客(梦婷轩
我的百度空间(梦婷轩

目录
相关文章
|
1月前
|
JSON Shell Linux
Shell获得Curl命令返回的json值
使用curl命令,获取solr中query的结果笔数 Linux中Shell获得json中的值
21 0
|
1月前
|
PHP 数据格式
PHP 中的CURL 模拟表单的post提交
PHP 中的CURL 模拟表单的post提交
16 0
|
7月前
|
JavaScript 前端开发 测试技术
关于 HTTP post 请求 form data 里的特殊符号,比如加号 plus symbol
关于 HTTP post 请求 form data 里的特殊符号,比如加号 plus symbol
88 0
|
9月前
|
API
Post 提交错误 远程服务器返回错误: (411) 所需的长度
Post 提交错误 远程服务器返回错误: (411) 所需的长度
72 0
|
JSON 数据安全/隐私保护 数据格式
CURL常用命令记录--用于简单测试接口
CURL常用命令记录--用于简单测试接口
163 0
|
Web App开发 应用服务中间件 Apache
Get/POST方法提交的长度限制
 1.    Get方法长度限制 Http Get方法提交的数据大小长度并没有限制,HTTP协议规范没有对URL长度进行限制。这个限制是特定的浏览器及服务器对它的限制。 如:IE对URL长度的限制是2083字节(2K+35)。 下面就是对各种浏览器和服务器的最大处理能力做一些说明. Microsoft Internet Explorer (Browser) IE浏览器对URL的最大限制
9453 0
|
网络协议
|
网络协议
|
编解码 应用服务中间件
表单提交方式由POST改为GET出现乱码的解决
组合查询功能,原先使用<html:form>缺省是以POST方式提交的,增加了分页功能后,由于要在URL里记住用户提交的查询内容(例如:http://localhost:8080/aims/client/filter.do?name=%E5%BC%A0&address=%E5%8C%97%E4%BA%AC&title=&duty=&departmentCode=10000001&categoryCode=10000002&fieldCode=10000006&genderCode=&identityCode=),所以表单的提交方式要改为GET。
1101 0