Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

POST binary file with cmd line curl using headers contained in the file

Tags:

http

curl

I'm trying to send a binary file to a server over HTTP. The beginning of the file contains headers already

I'm trying to send a file using command line version of curl for windows like so:

C:>curl  -H "Content-Type:application/octet-stream" --data-binary @asdf.file http://server:1234/url 

Curl is adding headers which cause a 400 Bad Request.

When I run the exact same command using the linux version of curl, the post completes?

like image 999
nbathum Avatar asked Oct 29 '10 16:10

nbathum


People also ask

How do I add a header to my curl POST?

To send an HTTP header with a Curl request, you can use the -H command-line option and pass the header name and value in "Key: Value" format. If you do not provide a value for the header, this will remove the standard header that Curl would otherwise send.

How do I POST a file using curl?

To post a file with Curl, use the -d or -F command-line options and start the data with the @ symbol followed by the file name. To send multiple files, repeat the -F option several times.

How do I send contents as body entity with curl?

curl will strip all newlines from the file. If you want to send the file with newlines intact, use --data-binary in place of --data . now how would one add login credentials to authorize this request? @anon58192932 - That depends upon the security protocol of the server.


1 Answers

Use

curl --header "Content-Type:application/octet-stream" --trace-ascii debugdump.txt --data-binary @asdf.file http://server:1234/url 

Or

Install wireshark or fiddler in windows to see the http request that flows over the network.

check the headers and the values being sent. Curl adds few headers by default. These default headers may be incompatible/not-accepted by the http server you connect to in case of windows.

To modify the value of header (added by default), you can add header followed by semi-colon. For example, Content-Type; to set the value null.

like image 80
Xan Avatar answered Oct 03 '22 14:10

Xan