使用 curl 发布二进制数据 [英] Binary Data Posting with curl
问题描述
所以基本上,我正在尝试编写一系列脚本来与 Dot Net Nuke 进行交互.我一直在分析流量,现在可以登录并执行一些基本任务.但是,我从来没有用 curl 处理过二进制文件上传.有人愿意看看这个来帮助我吗?这是请求的剖析:
到目前为止,这是我对 curl 的了解:
对于懒人 -
获取文件的长度并存储在LENGTH中
STUFF 只是带有参数的请求 URL 的复制/粘贴,减去 URL 本身.
curl -L --cookie ~/.cms --data-binary "@background.jpg" --header "内容长度:$LENGTH" --header "内容配置:表单数据" --header "name="RadFileExplorer1_upload1file0"" --header "Content-Type: image/jpg" --header "文件名="background.jpg"" --data $STUFF --referer "保密" 保密"
你不需要--header "Content-Length: $LENGTH".
<前>curl --request POST --data-binary "@template_entry.xml" $URL请注意,GET 请求不支持广泛的内容正文.
还要记住 POST 请求有 2 种不同的编码模式.这是第一种形式:
<前>$ nc -l -p 6666 &$ curl --request POST --data-binary "@README" http://localhost:6666POST/HTTP/1.1用户代理:curl/7.21.0 (x86_64-pc-linux-gnu) libcurl/7.21.0 OpenSSL/0.9.8o zlib/1.2.3.4 libidn/1.15 libssh2/1.2.6主机:本地主机:6666接受: */*内容长度:9309内容类型:应用程序/x-www-form-urlencoded期望:100-继续.. -*- 模式:第一个;编码:cp1251;填充列:80 -*-.. rst2html.py README README.html.. 内容::您可能会要求:
<前>-F/--表单名称=内容(HTTP) 这让 curl 在用户按下了提交按钮.这导致 curl 使用 ContentType POST 数据multipart/form-data 根据 RFC2388.这允许上传二进制文件等.强制'content' 部分是一个文件,在文件名前加上前缀带有@ 符号.只是从一个文件,在文件名前加上符号 <.这@ 和 < 之间的区别那么@使一个文件作为文件上传附加在帖子中,而 <制作一个文本字段,然后获取文件中该文本字段的内容.So basically, I'm trying to write a series of scripts to interact with Dot Net Nuke. I've been analysing the traffic and can now login and do some basic tasks. However, I've never handled binary file upload with curl. Would someone be willing to look at this to help me out? Here's the anatomy of the request:
Here's what I've got for curl so far:
edit: For the lazy -
length of the file is achieved and stored in LENGTH
STUFF is just a copy/paste of the request URL with parameters, minus the URL itself.
curl -L --cookie ~/.cms --data-binary "@background.jpg"
--header "Content-Length: $LENGTH"
--header "Content-Disposition: form-data"
--header "name="RadFileExplorer1_upload1file0""
--header "Content-Type: image/jpg"
--header "Filename="background.jpg""
--data $STUFF
--referer "Kept-Secret"
"Kept-Secret"
You don't need --header "Content-Length: $LENGTH".
curl --request POST --data-binary "@template_entry.xml" $URL
Note that GET request does not support content body widely.
Also remember that POST request have 2 different coding schema. This is first form:
$ nc -l -p 6666 & $ curl --request POST --data-binary "@README" http://localhost:6666 POST / HTTP/1.1 User-Agent: curl/7.21.0 (x86_64-pc-linux-gnu) libcurl/7.21.0 OpenSSL/0.9.8o zlib/1.2.3.4 libidn/1.15 libssh2/1.2.6 Host: localhost:6666 Accept: */* Content-Length: 9309 Content-Type: application/x-www-form-urlencoded Expect: 100-continue .. -*- mode: rst; coding: cp1251; fill-column: 80 -*- .. rst2html.py README README.html .. contents::
You probably request this:
-F/--form name=content (HTTP) This lets curl emulate a filled-in form in which a user has pressed the submit button. This causes curl to POST data using the Content- Type multipart/form-data according to RFC2388. This enables uploading of binary files etc. To force the 'content' part to be a file, prefix the file name with an @ sign. To just get the content part from a file, prefix the file name with the symbol <. The difference between @ and < is then that @ makes a file get attached in the post as a file upload, while the < makes a text field and just get the contents for that text field from a file.
这篇关于使用 curl 发布二进制数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!