Chinaunix

标题: curl 上传数据的问题 [打印本页]

作者: bitmilong    时间: 2005-11-29 22:05
标题: curl 上传数据的问题
用curl能以各种协议下载,它有没有上传数据的功能呢?
比如说CU发表话题(或回复)的表单的提交?

[ 本帖最后由 bitmilong 于 2005-11-30 21:53 编辑 ]
作者: mq110    时间: 2005-11-29 22:09
可以的.
不过涉及到表单可就复杂了.有的有hidden的.还有验证表单的方式也不相同.
作者: bitmilong    时间: 2005-11-29 22:35
谢谢110,你说的是这个吧

-d/--data <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 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 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'.

If you start the data with the letter @, the rest should be a file name to read the data from, or - if you want curl to read the data from stdin. The contents of the file must already be url-encoded. Multiple files can also be specified. Posting data from a file named 'foobar' would thus be done with --data @foobar".

To post data purely binary, you should instead use the --data-binary option.

-d/--data is the same as --data-ascii.

If this option is used several times, the ones following the first will append data.

作者: bitmilong    时间: 2005-11-29 22:46
原帖由 mq110 于 2005-11-29 22:09 发表
可以的.
不过涉及到表单可就复杂了.有的有hidden的.还有验证表单的方式也不相同.




type="hidden" 是指什么意思 ?
作者: mq110    时间: 2005-11-30 12:30
原帖由 bitmilong 于 2005-11-29 22:46 发表




type="hidden" 是指什么意思 ?


隐藏域.有些数据可以隐式的提交的.好久都没做网站了 汗.

不同的动态网页由于设计者的不同 而采取不同的方式.拿CU来说.想要做个自动表单提交的程序可不容易.有验证码的.需要你能够找到一个方式来处理验证码. 所以不提倡用CURL来做. 太麻烦啦.

[ 本帖最后由 mq110 于 2005-11-30 12:56 编辑 ]
作者: bitmilong    时间: 2005-11-30 21:53
原帖由 mq110 于 2005-11-30 12:30 发表


隐藏域.有些数据可以隐式的提交的.好久都没做网站了 汗.

不同的动态网页由于设计者的不同 而采取不同的方式.拿CU来说.想要做个自动表单提交的程序可不容易.有验证码的.需要你能够找到一个方式来处理验证码 ...




只是举个例子,做CU的自动表单提交也没啥意思,俺又没想发广告

隐式的表单和非隐式的表单的提交有什么差别吗?

type="hidden" ,就是在页面中不显示,用curl的话影响不大,加个判断就成了吧
作者: mq110    时间: 2005-11-30 22:00
原帖由 bitmilong 于 2005-11-30 21:53 发表




只是举个例子,做CU的自动表单提交也没啥意思,俺又没想发广告

隐式的表单和非隐式的表单的提交有什么差别吗?

type="hidden" ,就是在页面中不显示,用curl的话影响不大,加个判断就成了吧


有差别的. 以前我做网站的时候(php) 曾经加过隐藏的域.提交过来的数据判断一下. 现在的问题是 如果你没有动态页的代码.很有可能你写出来的程序最终会提交失败.
作者: bitmilong    时间: 2005-11-30 22:58
原帖由 mq110 于 2005-11-30 22:00 发表


有差别的. 以前我做网站的时候(php) 曾经加过隐藏的域.提交过来的数据判断一下. 现在的问题是 如果你没有动态页的代码.很有可能你写出来的程序最终会提交失败.



这是个问题,还没有找到类似的例子,得试试才行


btw:通过这两天对curl的研究,确实佩服其功能的强大




欢迎光临 Chinaunix (http://bbs.chinaunix.net/) Powered by Discuz! X3.2