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!

4 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!

  3. Currently working on a Stripe integration where I had the same need.

    I’ve also found the following iteration quite useful to make sure you are sending back the right headers.

    [code]curl -X POST http://localhost/app/test.php –data @data.txt -D- -o/dev/null -s[‘code]

    -D- will output the headers
    -o/dev/null will omit the returned body
    -s will not show the progress bar

Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.