WebRequest: How to ignore wrong response content type?

Im using a WebAPI from a widget. One of these requests is a authenticate request passing an auth token and the response is returning an bearer token.

The problem is, that the response it using "content-type: application/json" as responde header, but the body is plain text.



I filled the options with this setting to force a plain text response.

        var options = {
            :responseType => Communications.HTTP_RESPONSE_CONTENT_TYPE_TEXT_PLAIN,
            :method => Communications.HTTP_REQUEST_METHOD_POST,
            :headers => {
                "Content-Type" => Communications.REQUEST_CONTENT_TYPE_URL_ENCODED,
                "Authorization" => "Bearer "+ mAccessToken
            }

That is working on a fenix 5xplus, but on fenix6, fenix7 or Epix, a responsecode -400 is returned instead.

Can I somehow ignore that content check? It's fine if Garmin wants to help to check for corrent type, but in this case it's very frustrating. I can't change the WebAPI and I cant get the Garmin API to use my given option as content type.

How can I solve this problem?


Edit:
I got answer from the WebAPI owner:
The body is a valid JSON (string).
So my question is:
Why am I getting an -400 error when using JSON as result content-type?

        var options = {
            :responseType => Communications.HTTP_RESPONSE_CONTENT_TYPE_JSON,
            :method => Communications.HTTP_REQUEST_METHOD_POST,
            :headers => {
                "Content-Type" => Communications.REQUEST_CONTENT_TYPE_URL_ENCODED,
                "Authorization" => "Bearer "+ mAccessToken
            }

Response body:

"eyJhbGciOiJSUzUxMiIsI..."

: Is this an expected error or is it a bug? Shouln't the data result be teh parsed string when using HTTP_RESPONSE_CONTENT_TYPE_JSON?


Edit:
I'm wondering if this is an error which only is present in the simulator.
It seems, that the JSON string is parsed correct in the device with option HTTP_RESPONSE_CONTENT_TYPE_JSON.
But it returns an error -400 in simulator.

I made a fallback function if JSON option results in -400 error to try again with option HTTP_RESPONSE_CONTENT_TYPE_TEXT_PLAIN to get it workin in simulator. But that's a bit ugly.
Could this someone from Garmin please test and confirm? Many thanks!

  • GCM on the phone is a proxy so this could be something in iOS.  What about the version of GCM in both cases?  Can you try the f5+ with iOS or the f7s with Android?

    iOS used to have issues if you tried to include parameters in the url but the same thing worked on Android for example.

  • Hello

    I tested with the fenix7s in connection with an Android phone. There it's working with a plain text result of the JSON string body.
    It seems it's a bug in the GCM iOS app. The iOS GCM app is not passing back the content as plain text if the option HTTP_RESPONSE_CONTENT_TYPE_TEXT_PLAIN is set.

    Could you please forward this issue internally to the app team? It woul dbe nice if this issue can be fixed, that the iOS GCM app is returning the http body as plain text if requested. Many thanks.
    If you can't forward, please let me know where to create a support ticket.

    Regards
    Ronny