您的位置:首页 > 其它

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

2008-10-16 14:40 337 查看
今天偶然遇到一个情况,我想用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博客(梦婷轩

我的百度空间(梦婷轩
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: