HttpRequest
To send requests to any resource on the network and fetch the responseSending a JSON Object and String data as a Request
Use one of the following:
//Directly sending JSON object httpclient.send(postdata);
//Converting JSON object to JSON string and sending var jsonStr1 = JSON.stringify(postdata); httpclient.send(jsonStr1);
//Sending JSON string
var jsonStr2= "{\"userId\":\"test\",\"password\":\"test123\"}";
httpclient.send(jsonStr2);
Example :-
define({
onNavigate : function(objectEvent){
this.view.btnServiceCallEvent.onClick = this.onServiceCallEventFun;
},
onServiceCallEventFun : function(){
var httpclient = new kony.net.HttpRequest();
httpclient.open(constants.HTTP_METHOD_POST, "https://neutrinoapi.com/email-validate");
httpclient.setRequestHeader("user-id", "chandru");
httpclient.setRequestHeader("api-key", "5wPeyo4c9dFcUIyWMTghQP80nj3k0uyJzgals0MNKQ9wAjyf");
httpclient.setRequestHeader("Content-Type", "application/json");
var postdata = {
"email":"chandbecse@gmail.com",
"fix-typos":true
};
httpclient.timeout = 20000;
httpclient.onReadyStateChange = function(response){
kony.print("Result valid ==> "+response.valid);
kony.print("Result provider ==> "+response.provider);
kony.print("Result domain ==> "+response.domain);
kony.print("Result Response ==> :"+JSON.stringify(response));
};
httpclient.send(postdata);
}
});
Example Videos :