Error -400 webrequest to http server on iphone using app on Fenix 6s

I think i have tried every combination possible to make this work but cannot get anything except iq! or error -400

The curl output (from Mac attached to iphone hotspot):

markbushell@Marks-MacBook-Pro ~ % curl -v -k -L "172.20.10.1:11111" -o curl.txt

  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current

                                 Dload  Upload   Total   Spent    Left  Speed

  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0*   Trying 172.20.10.1...

* TCP_NODELAY set

* Connected to 172.20.10.1 (172.20.10.1) port 11111 (#0)

> GET / HTTP/1.1

> Host: 172.20.10.1:11111

> User-Agent: curl/7.64.1

> Accept: */*

> 

< HTTP/1.1 200 OK

< Cache-Control: no-cache

< Content-Length: 9076

< Content-Type: application/json

< Connection: Close

< Server: GCDWebServer

< Date: Sat, 03 Apr 2021 10:18:17 GMT

< 

{ [2796 bytes data]

100  9076  100  9076    0     0   295k      0 --:--:-- --:--:-- --:--:--  305k

* Closing connection 0

I cannot attach code as it say i am blocked from forums.garmin.com when i add the code?

  • Here is the output recieved from the web server:

    {
      "status" : [
        {
          "now" : 1617445097362
        }
      ],
      "bgs" : [
        {
          "device" : "miaomiao",
          "trend" : 3,
          "sgv" : "16.2",
          "datetime" : 1617445031194,
          "battery" : 90,
          "type" : "sgv",
          "delta" : 0,
          "units_hint" : "mmol"
        },
        {
          "device" : "miaomiao",
          "trend" : 3,
          "sgv" : "16.2",
          "datetime" : 1617444731476,
          "battery" : 90,
          "type" : "sgv",
          "delta" : 0
        },
        {
          "device" : "miaomiao",
          "trend" : 3,
          "sgv" : "16.3",
          "datetime" : 1617444425813,
          "battery" : 90,
          "type" : "sgv",
          "delta" : 0
        },
        {
          "device" : "miaomiao",
          "trend" : 3,
          "sgv" : "16.9",
          "datetime" : 1617443964129,
          "battery" : 90,
          "type" : "sgv",
          "delta" : 0
        },
        {
          "device" : "miaomiao",
          "trend" : 3,
          "sgv" : "17.5",
          "datetime" : 1617443658171,
          "battery" : 90,
          "type" : "sgv",
          "delta" : 0
        },
        {
          "device" : "miaomiao",
          "trend" : 3,
          "sgv" : "17.6",
          "datetime" : 1617443532564,
          "battery" : 90,
          "type" : "sgv",
          "delta" : 0
        },
        {
          "device" : "miaomiao",
          "trend" : 3,
          "sgv" : "18.0",
          "datetime" : 1617443177472,
          "battery" : 90,
          "type" : "sgv",
          "delta" : 0
        },
        {
          "device" : "miaomiao",
          "trend" : 3,
          "sgv" : "18.0",
          "datetime" : 1617442936574,
          "battery" : 90,
          "type" : "sgv",
          "delta" : 0
        },
        {
          "device" : "miaomiao",
          "trend" : 3,
          "sgv" : "18.1",
          "datetime" : 1617442642636,
          "battery" : 90,
          "type" : "sgv",
          "delta" : 0
        },
        {
          "device" : "miaomiao",
          "trend" : 3,
          "sgv" : "18.1",
          "datetime" : 1617442342802,
          "battery" : 90,
          "type" : "sgv",
          "delta" : 0
        },
        {
          "device" : "miaomiao",
          "trend" : 3,
          "sgv" : "18.2",
          "datetime" : 1617442287866,
          "battery" : 90,
          "type" : "sgv",
          "delta" : 0
        },
        {
          "device" : "miaomiao",
          "trend" : 3,
          "sgv" : "18.5",
          "datetime" : 1617442042308,
          "battery" : 90,
          "type" : "sgv",
          "delta" : 0
        },
        {
          "device" : "miaomiao",
          "trend" : 3,
          "sgv" : "18.4",
          "datetime" : 1617441742330,
          "battery" : 90,
          "type" : "sgv",
          "delta" : 0
        },
        {
          "device" : "miaomiao",
          "trend" : 3,
          "sgv" : "18.5",
          "datetime" : 1617441442674,
          "battery" : 90,
          "type" : "sgv",
          "delta" : 0
        },
        {
          "device" : "miaomiao",
          "trend" : 3,
          "sgv" : "18.5",
          "datetime" : 1617441381883,
          "battery" : 90,
          "type" : "sgv",
          "delta" : 0
        },
        {
          "device" : "miaomiao",
          "trend" : 3,
          "sgv" : "18.7",
          "datetime" : 1617441137530,
          "battery" : 90,
          "type" : "sgv",
          "delta" : 0
        },
        {
          "device" : "miaomiao",
          "trend" : 3,
          "sgv" : "18.4",
          "datetime" : 1617440707943,
          "battery" : 90,
          "type" : "sgv",
          "delta" : 0
        },
        {
          "device" : "miaomiao",
          "trend" : 3,
          "sgv" : "18.4",
          "datetime" : 1617440407918,
          "battery" : 90,
          "type" : "sgv",
          "delta" : 0
        },
        {
          "device" : "miaomiao",
          "trend" : 3,
          "sgv" : "18.5",
          "datetime" : 1617440107444,
          "battery" : 90,
          "type" : "sgv",
          "delta" : 0
        },
        {
          "device" : "miaomiao",
          "trend" : 3,
          "sgv" : "19.4",
          "datetime" : 1617439807308,
          "battery" : 90,
          "type" : "sgv",
          "delta" : 0
        },
        {
          "device" : "miaomiao",
          "trend" : 3,
          "sgv" : "17.4",
          "datetime" : 1617439504657,
          "battery" : 90,
          "type" : "sgv",
          "delta" : 0
        },
        {
          "device" : "miaomiao",
          "trend" : 3,
          "sgv" : "17.3",
          "datetime" : 1617439204406,
          "battery" : 90,
          "type" : "sgv",
          "delta" : 0
        },
        {
          "device" : "miaomiao",
          "trend" : 3,
          "sgv" : "16.9",
          "datetime" : 1617438904152,
          "battery" : 90,
          "type" : "sgv",
          "delta" : 0
        },
        {
          "device" : "miaomiao",
          "trend" : 3,
          "sgv" : "18.5",
          "datetime" : 1617438604380,
          "battery" : 90,
          "type" : "sgv",
          "delta" : 0
        },
        {
          "device" : "miaomiao",
          "trend" : 3,
          "sgv" : "18.3",
          "datetime" : 1617438304390,
          "battery" : 90,
          "type" : "sgv",
          "delta" : 0
        },
        {
          "device" : "miaomiao",
          "trend" : 3,
          "sgv" : "17.0",
          "datetime" : 1617438004290,
          "battery" : 90,
          "type" : "sgv",
          "delta" : 0
        },
        {
          "device" : "miaomiao",
          "trend" : 3,
          "sgv" : "17.1",
          "datetime" : 1617437704846,
          "battery" : 90,
          "type" : "sgv",
          "delta" : 0
        },
        {
          "device" : "miaomiao",
          "trend" : 3,
          "sgv" : "17.9",
          "datetime" : 1617437400073,
          "battery" : 90,
          "type" : "sgv",
          "delta" : 0
        },
        {
          "device" : "miaomiao",
          "trend" : 3,
          "sgv" : "16.3",
          "datetime" : 1617437097763,
          "battery" : 90,
          "type" : "sgv",
          "delta" : 0
        },
        {
          "device" : "miaomiao",
          "trend" : 3,
          "sgv" : "17.5",
          "datetime" : 1617436797751,
          "battery" : 90,
          "type" : "sgv",
          "delta" : 0
        },
        {
          "device" : "miaomiao",
          "trend" : 3,
          "sgv" : "17.3",
          "datetime" : 1617436497614,
          "battery" : 90,
          "type" : "sgv",
          "delta" : 0
        },
        {
          "device" : "miaomiao",
          "trend" : 3,
          "sgv" : "16.9",
          "datetime" : 1617436197569,
          "battery" : 90,
          "type" : "sgv",
          "delta" : 0
        },
        {
          "device" : "miaomiao",
          "trend" : 3,
          "sgv" : "16.3",
          "datetime" : 1617435897388,
          "battery" : 90,
          "type" : "sgv",
          "delta" : 0
        },
        {
          "device" : "miaomiao",
          "trend" : 3,
          "sgv" : "15.7",
          "datetime" : 1617435597668,
          "battery" : 90,
          "type" : "sgv",
          "delta" : 0
        },
        {
          "device" : "miaomiao",
          "trend" : 3,
          "sgv" : "15.6",
          "datetime" : 1617435298972,
          "battery" : 90,
          "type" : "sgv",
          "delta" : 0
        },
        {
          "device" : "miaomiao",
          "trend" : 3,
          "sgv" : "15.8",
          "datetime" : 1617434992020,
          "battery" : 90,
          "type" : "sgv",
          "delta" : 0
        },
        {
          "device" : "miaomiao",
          "trend" : 3,
          "sgv" : "15.1",
          "datetime" : 1617434692842,
          "battery" : 90,
          "type" : "sgv",
          "delta" : 0
        },
        {
          "device" : "miaomiao",
          "trend" : 3,
          "sgv" : "15.2",
          "datetime" : 1617434394127,
          "battery" : 90,
          "type" : "sgv",
          "delta" : 0
        },
        {
          "device" : "miaomiao",
          "trend" : 3,
          "sgv" : "15.1",
          "datetime" : 1617434092044,
          "battery" : 90,
          "type" : "sgv",
          "delta" : 0
        },
        {
          "device" : "miaomiao",
          "trend" : 3,
          "sgv" : "15.2",
          "datetime" : 1617433792291,
          "battery" : 90,
          "type" : "sgv",
          "delta" : 0
        },
        {
          "device" : "miaomiao",
          "trend" : 3,
          "sgv" : "15.4",
          "datetime" : 1617433492684,
          "battery" : 90,
          "type" : "sgv",
          "delta" : 0
        },
        {
          "device" : "miaomiao",
          "trend" : 3,
          "sgv" : "14.8",
          "datetime" : 1617433193209,
          "battery" : 90,
          "type" : "sgv",
          "delta" : 0
        },
        {
          "device" : "miaomiao",
          "trend" : 3,
          "sgv" : "13.8",
          "datetime" : 1617432887698,
          "battery" : 90,
          "type" : "sgv",
          "delta" : 0
        },
        {
          "device" : "miaomiao",
          "trend" : 3,
          "sgv" : "13.5",
          "datetime" : 1617432588318,
          "battery" : 90,
          "type" : "sgv",
          "delta" : 0
        },
        {
          "device" : "miaomiao",
          "trend" : 3,
          "sgv" : "14.5",
          "datetime" : 1617432287339,
          "battery" : 90,
          "type" : "sgv",
          "delta" : 0
        },
        {
          "device" : "miaomiao",
          "trend" : 3,
          "sgv" : "14.3",
          "datetime" : 1617431987425,
          "battery" : 90,
          "type" : "sgv",
          "delta" : 0
        },
        {
          "device" : "miaomiao",
          "trend" : 3,
          "sgv" : "14.3",
          "datetime" : 1617431687306,
          "battery" : 90,
          "type" : "sgv",
          "delta" : 0
        },
        {
          "device" : "miaomiao",
          "trend" : 3,
          "sgv" : "14.3",
          "datetime" : 1617431387627,
          "battery" : 90,
          "type" : "sgv",
          "delta" : 0
        },
        {
          "device" : "miaomiao",
          "trend" : 3,
          "sgv" : "14.3",
          "datetime" : 1617431087404,
          "battery" : 90,
          "type" : "sgv",
          "delta" : 0
        },
        {
          "device" : "miaomiao",
          "trend" : 3,
          "sgv" : "14.3",
          "datetime" : 1617430787716,
          "battery" : 90,
          "type" : "sgv",
          "delta" : 0
        }
      ],
      "cals" : [
    
      ]
    }

    And my code:

    using Toybox.Communications;
    using Toybox.WatchUi;

    class TomatoCheckerView extends WatchUi.View {
    var version = "0.0.134";
    var notify;
    var BGData;
    //var dataURL = "127.0.0.1:11111/index.htm"; //error -400
    //var dataURL = "127.0.0.1:11111"; //error -400
    //var dataURL = "127.0.0.1:11111/index.htm"; //error -400
    //var dataURL = "">127.0.0.1:11111/index.htm"; //iq with !
    //var dataURL = "">osm.zizsu.com/Response.txt";
    //var dataURL = "">http://localhost:11111";
    var dataURL = "localhost:11111"; //error -400
    //var dataURL = "">http://127.0.0.1:11111"; //iq with !

    // Handle menu button press
    function onMenu() {
    makeRequest();
    return true;
    }

    function onSelect() {
    makeRequest();
    return true;
    }

    function initialize() {
    View.initialize();
    //WatchUi.BehaviorDelegate.initialize();
    }

    // Load your resources here
    function onLayout(dc) {
    setLayout(Rez.Layouts.MainLayout(dc));
    }

    // Called when this View is brought to the foreground. Restore
    // the state of this View and prepare it to be shown. This includes
    // loading resources into memory.
    function onShow() {
    makeRequest();
    return true;
    }

    // Update the view
    function onUpdate(dc) {
    // Call the parent onUpdate function to redraw the layout
    View.onUpdate(dc);

    }

    // Called when this View is removed from the screen. Save the
    // state of this View here. This includes freeing resources from
    // memory.
    function onHide() {
    }

    function makeRequest() {

    var params = {};

    var options = { // set the options
    :method => Communications.HTTP_REQUEST_METHOD_GET,
    //:headers => {"Content-Type" => Communications.REQUEST_CONTENT_TYPE_URL_ENCODED},
    :headers => {"Content-Type" => Communications.REQUEST_CONTENT_TYPE_JSON},
    //:responseType => Communications.HTTP_RESPONSE_CONTENT_TYPE_TEXT_PLAIN
    :responseType => Communications.HTTP_RESPONSE_CONTENT_TYPE_JSON
    //:responseType => Communications.HTTP_RESPONSE_CONTENT_TYPE_URL_ENCODED
    };


    /*
    var options = { // set the options
    :method => Communications.HTTP_REQUEST_METHOD_GET,
    :headers => {"Content-Type" => Communications.REQUEST_CONTENT_TYPE_URL_ENCODED},
    :responseType => Communications.HTTP_RESPONSE_CONTENT_TYPE_TEXT_PLAIN
    //:responseType => Communications.HTTP_RESPONSE_CONTENT_TYPE_JSON
    //:responseType => Communications.HTTP_RESPONSE_CONTENT_TYPE_URL_ENCODED
    };

    var options =
    {
    :method => Communications.HTTP_REQUEST_METHOD_GET,
    :responseType => Communications.HTTP_RESPONSE_CONTENT_TYPE_TEXT_PLAIN
    };
    */
    var responseCallback = method(:onReceiveData);

    Communications.makeWebRequest(dataURL, params, options, method(:onReceiveData));

    }

    // Receive the data from the web request
    function onReceiveData(responseCode, data) {
    if (responseCode == 200) {

    System.println("in onReceive, responseCode=" + responseCode + ", data=" + data);
    //mainlayout.BGLevelLabel.Test = data;
    BGData = data.toString();
    //Lets Try to Get just the BG
    //find the sgv
    var BGLocation = BGData.find("\"sgv\" : \"");
    var BG = BGData.substring(BGLocation + 9, BGLocation + 16);
    var strBG = "BG: " + BG.toString() + "\nLocation: " + BGLocation.toString() + "\n" + version.toString();

    var drw = self.findDrawableById("BGLevelLabel");
    drw.setText(strBG);

    WatchUi.requestUpdate();
    }
    else {
    System.println("Response: " + responseCode + "\nData: " + data);

    var drw = self.findDrawableById("BGLevelLabel");
    drw.setText("Error: " + responseCode.toString() + "\n" + dataURL.toString() + "\n" + version.toString() + "\nData: " + data);

    WatchUi.requestUpdate();
    }
    }
    }

  • INVALID_HTTP_BODY_IN_NETWORK_RESPONSE -400

    1.0.0

    Response body data is invalid for the request type.

    Sounds like the server isn't returning the data in the format requested. (text when you are expecting json, etc)

    With the iq!, that means your app crashed.  On a real device you can see the crash in apps\logs\ciq_log.yml

  • Thanks for the reply, I have tried every combination of URL, Repsonse and Request.

    Thanks for the crashlog tip I am getting response code 200 when using http:// url so i think the code here is crashing.

  • Thanks again, the error log was the helper although it worked fine using the simulator and web txt file.