Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

curl HTTP post

Status
Not open for further replies.

razalas

Programmer
Apr 23, 2002
237
US
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:
Code:
Content-type: multipart/mixed; boundary=BOUNDARY
Content-length: nnnn

--BOUNDARY
Content-type: application/x-[URL unfurl="true"]www-form-urlencoded[/URL]
Content-length: nnn

Parm1=Data1&Parm2=Data2&Parm3=...

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

<bunch of binary data>

--BOUNDARY--

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:
Code:
curl --include --header "Content-type: multipart/mixed; boundary=BOUNDARY" --header "Content-length: 1493" --data-binary @my-bin-file --output my-output-file [URL unfurl="true"]https://www.my-business-partner.com/incoming[/URL]

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!

Razalas
 
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/1.2.1.2 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!

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



 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top