Posting Raw Data with Curl

This week I've been working on a feature which handles an incoming API call from an external source (actually Paypal's IPN service). Making external calls into my development platform isn't how I usually work, so instead I captured the body of the request that was being sent, and replayed it against my local script using curl.

I put the data into a separate file, data.txt and then used curl to direct that data at my local URL:

curl -X POST http://localhost/app/test.php --data @data.txt

I find this approach useful for testing, but since I had to look up how to do it, I thought I'd put it here for reference!

3 thoughts on “Posting Raw Data with Curl

  1. Pingback: Github API Access Tokens via Curl | LornaJane

  2. Hi Lornajane,

    I know this post is a couple of year old, but it answered a question for me as I am getting more up to speed with Curl. I thought I'd share this in case someone else came here:

    Looking at the current man page, it looks like the '-X POST' option is redundant in that the '--data' option make the request a POST (see both '--data' and '-X' in man page for details.) So that said, the above could also be sent as:

    curl --data @data.txt http://localhost/app/test.php

    Small thing, but just thought I'd share what I figured out since I found your post helpful.

    Thanks!
    Eric

    • You're absolutely right, the -X is optional but I always like to include it for clarity.... that's clarity for me, not for curl!

Leave a Reply

Please use [code] and [/code] around any source code you wish to share.

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>