Dependent Origination

How to figure out why a third-party API isn’t returning what you expect

Posted on: May 17, 2012

The third-party provides example scripts using command line curl and they work well — so you know it must be your problem. The question is how to figure out what your problem is.

Things I find useful along the way:

1. Postman Google Chrome Extension — you can search it in Chrome Web Store — very easy to use, simple and intuitive interface, really good tool to try out an HTTP API

2. Luckily our C++ code of a HTTP client can print out the raw request if you lower the debug level so I get a raw HTTP request easily. You have to figure out if using other bindings/libraries.

3. Use netcat host port < request.txt to send the host a raw http request you obtain from step 2. you can tweak your raw request here to make it work 🙂 you can use telnet host 80 and paste that request too but netcat is better if you tweak your requests.

4. Unfortunately you cannot make it work with simple tweaks. the only thing now is getting the raw request from the working third-party script  and compare to our own. Curl makes it easy: use –verbose or –trace-ascii. –verbose in fact prints out the request (sans the actual form data part) while –trace-ascii is only printing out what curl receives from the host, so it is a little different from what Curl tutorial is saying about http scripting.

5. At this point, the two raw requests compare nicely: I am sending out the wrong Content-Type header and change it. All set.

Feel really good about figuring out this myself 🙂

For reference, this page lists the basics of HTTP GET/POST nicely.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

May 2012
« Apr   Jun »


Flickr Photos

%d bloggers like this: