Hi as per title, I don't see why this is not working on the device itself but works fine on the simulator?
The server side code simply receives the request in javascript as:
if (req.body.request && req.body.request === "urlplz") {
And here is the monkey c code:
function onReceive(responseCode as Number, data as Dictionary or String) as Void{
if (responseCode == 200) {
var idplz = Storage.getValue("id");
if (idplz == null) {
Storage.setValue("id", data["id"]);
}
if (data["yt"].equals("true")) {
mode= true;
Storage.setValue("mode", "true");
}
yes = data["url"];
WatchUi.pushView(new $.View(), new $.Delegate(), WatchUi.SLIDE_UP);
} else {
WatchUi.pushView(new $.View(), new $.Delegate(), WatchUi.SLIDE_UP);
}
}
function makeRequest() {
var idplz = Storage.getValue("id");
if (idplz == null) {
idplz = "notavailable";
}
var url = "myurl.url;
var params = { // set the parameters
"request" => "urlplz",
"urlcode" => idplz
};
var options = {
:method => Communications.HTTP_REQUEST_METHOD_POST,
:headers => {
"Content-Type" => Communications.REQUEST_CONTENT_TYPE_JSON
},
:responseType => Communications.HTTP_RESPONSE_CONTENT_TYPE_JSON
};
Communications.makeWebRequest(url, params, options, method(:onReceive));
}
AND I have also tried it this way which also works fine on the simulator but not the physical device, where I just swapped the params into the headers:
function onReceive(responseCode as Number, data as Dictionary or String) as Void{
if (responseCode == 200) {
var idplz = Storage.getValue("id");
if (idplz == null) {
Storage.setValue("id", data["id"]);
}
if (data["yt"].equals("true")) {
mode = true;
Storage.setValue("mode", "true");
}
yes = data["url"];
WatchUi.pushView(new $.View("okay"), new $.Delegate(), WatchUi.SLIDE_UP);
} else {
WatchUi.pushView(new $.View("error"), new $.Delegate(), WatchUi.SLIDE_UP);
}
}
function makeRequest() {
var idplz = Storage.getValue("id");
if (idplz == null) {
idplz = "notavailable";
}
var url = "myurl.url";
var options = {
:method => Communications.HTTP_REQUEST_METHOD_POST,
:headers => {
"Content-Type" => Communications.REQUEST_CONTENT_TYPE_JSON,
"request" => "url",
"urlplzsir" => code
},
:responseType => Communications.HTTP_RESPONSE_CONTENT_TYPE_JSON
};
Communications.makeWebRequest(url, null, options, method(:onReceive));
}
with the server side javascript code accepting it as:
if (req.headers['request'] && req.headers['request'] === "gimme") {