Coding with Titans

so breaking things happens constantly, but never on purpose

Tracing a HTTP request on mobile

Usually it’s not a big deal, when a HTTP request to a remote server is not working on a desktop Windows machine. There are plenty of useful tools, that could help in the process:

  • one, which work like a proxy and dump the whole traffic, that we might be interested in (Fiddler would be the best example here)

  • others, that interact with the TCP/IP stack itself and look much deeper for sent packets (like WireShark or Microsoft Message Analyzer - unfortunately retired as of 2020-01-20).

    BTW. Do you know, that there is a way to visualize HTTP traffic in Fiddler, that was originally captured by Wireshark or MMA? Simply export packets from WireShark as pcap file (File –> Export –> Export as .pcap file) and import it directly into Fiddler (File –> Import Session… –> Packet Capture). Many thanks to Rick Stahl, for showing me this feature.

    UPDATED: 2020-20-21
    BTW 2. Since Message Analyzer is discontinued, please take a look at this great comparison of alternatives prepared by Kevin Manning. Thanks for contacting me to share it!

Mobiles are totally different world. Mostly because applications are running in a dedicated sandbox and there isn’t at all internal or external access on system level. There is not much to do beside debugging of our own code. But if this doesn’t help, it doesn’t mean we stay blind. Take a look at http://httpbin.org/ (project sources available on GitHub). It’s the server you always wanted to write yourself – server that returns info about client accompanied by a list of headers, info about content for all kinds of submitted requests and even some random binary data, if you like. Respective behavior is selected by dedicated path on the httbin.org server and response is of course in JSON format (maybe beside for the binary data request).

Typically request paths:

  • /get
  • /post
  • /put
  • /delete – all of them to know, how the request really looks like
  • /status/<code> – to verify, if the application handles given error respectively
  • /bytes/<size>
  • /stream-bytes/<size> – both to download some random binary block of bytes from server. It won’t simulate your destination server at all nor any more advanced interactions. And you will need to to hack your application to be able to issue requests against this server and dump somewhere the JSON response. Still remember, it’s only during application development and while fighting with a non-working request against remote server you totally have no control over, so additional #ifdef won’t hurt at all ;)

Final thought – the trick described above could be also without any problem used inside desktop or Windows Store application. It’s not only dedicated to mobiles!