Matt
Matt

Reputation: 1187

cURL Post data from a file

I am trying to send a POST request to a server and would like the post data to be in a file. The page is looking for the number parameter. Currently, I have this command:

curl -i -X POST 127.0.0.1:80/page.php -H "Content-Type: text/xml" --data-binary "@postdata.txt"

The problem with this is that it does not post the data. This is what's inside the postdata.txt:

number=100&other=data

Upvotes: 2

Views: 272

Answers (1)

drew010
drew010

Reputation: 69977

What you are trying to do should work. The issue is most likely that you are setting the Content-Type to text/xml and you're not sending xml, you're sending application/x-www-form-urlencoded data. Also, there's absolutely no need to use -X since you're trying to do a standard post.

Try removing the Content-Type and let curl set it automatically:

curl -i --data-binary @postdata.txt http://127.0.0.1/page.php

You can also use shell command substitution but it's not necessary:

curl --data-binary $(cat postdata.txt) http://127.0.0.1/page.php

Upvotes: 2

Related Questions