Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here


curl HTTP post

curl HTTP post

curl HTTP post

Not sure if this is the best forum to post this, but hopefully somebody here might be able to point me in the right direction.

I am trying to POST an HTTP request to a business partner's web site using the Linux curl command, but I am having trouble sending all my content. They want the message formatted as a MIME message (Content-type: multipart/mixed), but I am beginning to wonder if I can to do this with curl. From the man page and what I can find on the web, I should be able to format the necessary headers, but curl doesn't seem to want to include all the data I am trying to send.

The message I am trying to POST is supposed to follow the format shown below:


Content-type: multipart/mixed; boundary=BOUNDARY
Content-length: nnnn

Content-type: application/x-www-form-urlencoded
Content-length: nnn


Content-type: application/x-appl-specific-type
Content-length: nnnn

<bunch of binary data>


I have everything after the first Content-length header in a file, lets call it "my-bin-file" for this example. My curl command is coded as follows:


curl --include --header "Content-type: multipart/mixed; boundary=BOUNDARY" --header "Content-length: 1493" --data-binary @my-bin-file --output my-output-file https://www.my-business-partner.com/incoming 

Running on RHEL: "User-Agent: curl/7.12.1 (x86_64-redhat-linux-gnu) libcurl/7.12.1"

The contents of my-bin-file do not appear to be getting included in the post. I get back a properly formatted response indicating the my POST was missing data. From what I can see curl is only including the first 15 bytes from my-bin-file, which doesn't make any sense to me.

Code what you mean,
and mean what you code!
But by all means post your code!


RE: curl HTTP post

Just in case anybody is interested, it seems like my problem was due to trying to append data using multiple --data-binary parameters. According to the man page, multiples of --data-binary should append data. I actually had three: one for everything up to the "binary data", one for the "binary data", and one for everything else. I changed to catentate all three pieces into a single file and then passed that single file using only one --data-binary and now it appears to be working correctly (or at least the site I POST'ing to, seems to recognize my message).

curl --version
curl 7.12.1 (x86_64-redhat-linux-gnu) libcurl/7.12.1 OpenSSL/0.9.7a zlib/ libidn/0.5.6
Protocols: ftp gopher telnet dict ldap http file https ftps
Features: GSS-Negotiate IDN IPv6 Largefile NTLM SSL libz

Code what you mean,
and mean what you code!
But by all means post your code!


RE: curl HTTP post

I don't have any experience using "curl", but I've had some success doing this using "wget". It can POST either a string or the contents of a file. Look for the command line options "--post-data" and "--post-file". You also have full control of headers and cookies being sent with the POST.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close