相关文章推荐
仗义的人字拖  ·  ajax ...·  1 年前    · 
不羁的面包  ·  mac安装lxml-西瓜视频·  1 年前    · 
健壮的芹菜  ·  RedHat 7 安装HTTPD_ITPUB博客·  2 年前    · 
闷骚的鸡蛋面  ·  StableLM 开源: ...·  2 年前    · 
Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

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:

http://pastebin.com/qU8ZEMaQ

Here's what I've got for curl so far:

http://pastebin.com/LG2ubFZG

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"

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. Thanks for the response. Unfortunately, nothing manages to happen. Would it be possible for you to take a quick look at the post anatomy? How would you add in something like:------WebKitFormBoundarymXQVUy6BiZBV3AxA Content-Disposition: form-data; name="RadFileExplorer1$currentFolder" /Portals/0/Images/Test/ to a curl command? Would that be via header? Or since it has a name would it be via regular post data? – user798080 Feb 3, 2012 at 19:58 As I proper remember for POST request there exist different coding schema (may be to manage FORM html tag??). – gavenkoa Feb 3, 2012 at 20:03 Well normally with curl you can say something like curl -d "username=cheese&password=123456" <url>, but it also looks drastically different when I inspect it with Chrome/Firebug. I certainly don't see Content-Disposition among other things. I don't know if there needs to be a special version of POST data when you're submitting plaintext and binary data. – user798080 Feb 3, 2012 at 20:07

Thanks for contributing an answer to Stack Overflow!

  • Please be sure to answer the question. Provide details and share your research!

But avoid

  • Asking for help, clarification, or responding to other answers.
  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.