Making POST request in SDK 1.2.0

Former Member
Former Member
I am attempting to make a POST request with the new SDK like so:

var options = { :method => Comm.HTTP_REQUEST_METHOD_POST };
Comm.makeJsonRequest("http://127.0.0.1:8000/", {}, options, method(:onReceive));


There isn't an error, but from my server I'm seeing that it's only doing a GET request. I'm definitely running SDK 1.2.0 since it compiles fine with the Comm.HTTP_REQUEST_METHOD_POST constant.
  • The new HTTP request methods require a new version of Garmin Connect Mobile, which is not yet available. I understand it's not ideal, but you can still develop and test with these new methods in the Connect IQ simulator. Since this was a beta SDK release, we tried to get as many features available as possible so developers can begin working with the new stuff, but there are a few things that won't be 100% functional until the full release. :)
  • Former Member
    Former Member over 9 years ago
    This should still work in the simulator, correct?
  • Yes, that is correct--POST requests should work in the simulator in the 1.2.0 SDK beta release.
  • Former Member
    Former Member over 9 years ago
    I've tried this every which way and still can't get it to work on the simulator. I've also tried using the custom headers with no luck. Is there an example somewhere of how to properly use this new options and parameters?
  • I can't get it to work either. I stuck a proxy in the middle, and I see that I'm not getting a POST request at all. Here is the original GET request code...

    var params = {
    "q" => "London"
    };

    var options = {
    //:method => Comm.HTTP_REQUEST_METHOD_POST,
    //:headers => { "Test-Header" => "Test-Value" }
    };

    Comm.makeJsonRequest("127.0.0.1:8080/.../weather",
    params,
    options,
    self.method(:onResponse));


    And here is the request that is being sent to the server...

    > 2015-10-04 20:54:35 tcptunnel: request from 127.0.0.1
    > 2015-10-04 20:54:35 > GET /data/2.5/weather?q=London HTTP/1.1
    User-Agent: Mozilla/5.0
    Host: 127.0.0.1:8080
    Accept: */*


    All is as expected so far. Now, if I uncomment the method specification and headers in the options map, I get the following HTTP request.

    > 2015-10-04 20:57:22 tcptunnel: request from 127.0.0.1
    > 2015-10-04 20:57:22 > GET /data/2.5/weather HTTP/1.1
    User-Agent: Mozilla/5.0
    Host: 127.0.0.1:8080
    Accept: */*


    Notice that the method is still GET. Notice also that the request parameters are not included in the url like you'd expect to see for a GET request. I'm also not seeing the data being sent in the request body, so it isn't a fully formed POST request either.

    Travis
  • Okay, we'll get this looked at. The various HTTP request methods are supposed to work in the beta SDK. ;) Thanks for investigating!