makeWebRequest Example

Former Member
Former Member
I have a web API that accepts the following REST POST



{
"heartRate": "95"
}

I can then do a GET and it will return anything that was previously posted.

I know I need to use the makeWebRequest, can some please provide an example of what this should look like in Monkey C?

This does not work for me - Comm.makeWebRequest("somewebsite.azurewebsites.net/.../HeartRates",{"heartRate"=> "55"},{"Content-Type" => 3},method(:onReceive));


THANKS
  • You should really take a look at the documentation for makeWebRequest().

    The first problem is that you you need to tell makeWebRequest() to POST the data. The problem is that the options parameter is not a map of headers, it is a map of options; one of those options is the headers to send with the request.

    I believe that makeWebRequest() is covered in one of the sample programs, but in case it isn't...

    var url = "somewebsite.azurewebsites.net/.../HeartRates";

    // request parameters
    var params = {
    "heartRate"=> 55
    };

    // request headers
    var headers = {
    // note that specifying the content-type with a GET or DELETE will force
    // the parameters to be sent in the body of the request
    "Content-Type" => Comm.REQUEST_CONTENT_TYPE_JSON
    };

    // options
    var options = {
    :headers => headers,
    :method => Comm.HTTP_REQUEST_METHOD_POST,
    :responseType => Comm.HTTP_RESPONSE_CONTENT_TYPE_JSON
    };

    Comm.makeWebRequest(url, params, options, method(:onReceive));


    Travis
  • Former Member
    Former Member over 8 years ago
    Thanks! :-)

    You should really take a look at the documentation for makeWebRequest().

    The first problem is that you you need to tell makeWebRequest() to POST the data. The problem is that the options parameter is not a map of headers, it is a map of options; one of those options is the headers to send with the request.

    I believe that makeWebRequest() is covered in one of the sample programs, but in case it isn't...

    var url = "somewebsite.azurewebsites.net/.../HeartRates";

    // request parameters
    var params = {
    "heartRate"=> 55
    };

    // request headers
    var headers = {
    // note that specifying the content-type with a GET or DELETE will force
    // the parameters to be sent in the body of the request
    "Content-Type" => Comm.REQUEST_CONTENT_TYPE_JSON
    };

    // options
    var options = {
    :headers => headers,
    :method => Comm.HTTP_REQUEST_METHOD_POST,
    :responseType => Comm.HTTP_RESPONSE_CONTENT_TYPE_JSON
    };

    Comm.makeWebRequest(url, params, options, method(:onReceive));


    Travis