Creating PUT webrequest with data

Hi, I'm new to monkey C, and I'm having trouble making a http PUT-request to send some data to an api.I have done the same thing in python:

import requests
url = 'http://...'
data = '{"on":true}'
r = requests.put(url, data=data, verify=False)


The trouble is I don't see how to include the data in monkey C. How would I include the data in monkey C?

var url = "">10.0.0.1/.../state";
var parameters = {};
var data =  "{\"on\": \"true\"}"
var options = {
     :method => Communications.HTTP_REQUEST_METHOD_PUT,
};
var responseCallback = method(:onRecieve);
Communications.makeWebRequest(url, parameters, options, responseCallback);

  • You want something like:

    var parameters = { "on" => "true" };

    The data needs to go into the parameters as a dictionary.

  • Thank you for the reply! Unfortunately i need just a string in the body of the http-request. Even though the example happens to be key-value pairs, it's not the format for the endpoint (which I do not control). Sorry about misleading example.

  • I don’t believe the communications module supports a request body of text / plain. You could try setting that header and setting params to a string and see what happens. But I don’t think it’ll work.  In your response call back add a System.println (responseCode + “ “ + data) and see what you get back.  Note some response codes are not standard http numbers but ones internal between your device and phone. The numbers and meaning are listed in the api docs.