Beware the -400 INVALID_HTTP_BODY_IN_NETWORK_RESPONSE error

This may be well known, and widely reported elsewhere, but it appears that makeWebRequest will return the -400 INVALID_HTTP_BODY_IN_NETWORK_RESPONSE error when a 404 (file not found) error would otherwise be expected.
I wasted spent many hours today vainly debugging my json when in fact there was some gremlin in the comms channel that was failing to find my file.



  • If the response Content-Type is not consistent with what is expected, or the actual response body cannot be parsed as content of that type, you will get a 404 response code. You can run into trouble if the service you are accessing returns JSON on success but sends back non-JSON data (typically HTML) in common error scenarios. If this is the case, it is a server-side issue.

    If you are debugging web requests/responses, the easiest thing to do is to setup a web proxy. For simple cases where HTTP is available on the server-side, I frequently use TCPtunnel for this. If HTTPS is required I will use Fiddler.

    Travis
  • I received a -400 INVALID_HTTP_BODY_IN_NETWORK_RESPONSE when I was doing an HTTP (not HTTPS) request from my "side loaded" Data Field via a connected phone (iPhone), with Wi-Fi connection turned off on a Garmin Edge device. I would have expected a -1001 (SECURE_CONNECTION_REQUIRED).

    I hope this helps anyone who is trying to solve the -400 INVALID_HTTP_BODY_IN_NETWORK_RESPONSE.

    Garmin Connect iOS app (4.42.1)
    Garmin Edge 830
    API Level 3.1