36

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?

mklement0
  • 382,024
  • 64
  • 607
  • 775
nbathum
  • 363
  • 1
  • 3
  • 6
  • 2
    I find it strange that curl would add headers leading to a bad request. You should try adding `-v` to see which headers curl is actually sending. – flesk Nov 25 '11 at 19:02

1 Answers1

56

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.

mleu
  • 365
  • 3
  • 5
Xan
  • 726
  • 8
  • 6
  • I was having a problem with suhosin on PHP. _ALERT - configured request variable name length limit exceeded - dropped variable_ The default content type is application/x-www-form-urlencoded and unless you explicitly specify it, you could trigger some sanity rules on some servers. This fixed the issue for me. – Phil Aug 11 '15 at 07:46
  • Lastly does anyone know how to set the filename on the destination side? `cat /tmp/12047.csv| curl -v -X POST --header "Content-Type:application/octet-stream" --data-binary @- someUrl` ? – Nick Sep 23 '16 at 18:44
  • I found that setting the name on the destination side depends on the other side's implementation. For my use case with the GitHub REST API, they have a name param that I pass like `POST https:///repos/:owner/:repo/releases/:release_id/assets?name=foo.zip` – wonderfulthunk Oct 23 '18 at 15:46