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
..."
Travis.ConnectIQ: 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!