kony.net.HttpRequest response return null

This thread was migrated from an old forum. It may contain information that are no longer valid. For further assistance, please post a new question or open a support ticket from the Customer Support portal.

I'm trying to get a response from a post Http Request when I try to run the app on web live preview I can show the response but when try to run it on my mobile device I'm always get this response:

{ text: null }

Here's my code:

var data = { domainName: 'test', password: 'password' }; request = new kony.net.HttpRequest(); request.onReadyStateChange = httpCallbackHandler; request.open(constants.HTTP_METHOD_POST, SCM_API_URL + 'login'); request.setRequestHeader("Content-Type", "application/json"); var jsonStr1 = JSON.stringify(data); request.send(jsonStr1);

function httpCallbackHandler() {
if (this.readyState == constants.HTTP_READY_STATE_DONE) {
var loginResponse = request.response;
if (IsJsonString(loginResponse)) {
JSON.parse(loginResponse);
}
if (loginResponse) {
kony.application.dismissLoadingScreen();
kony.ui.Alert({
“alertType”: constants.ALERT_TYPE_ERROR,
“alertTitle”: “error”,
“yesLabel”: “OK”,
“message”: "response: " + JSON.stringify(request.response)
}, {
“iconPosition”: constants.ALERT_ICON_POSITION_LEFT
});

           if (loginResponse.message && loginResponse.message.returnCode === 'Success') {
               headers = this.getAllResponseHeaders();
               token = headers['authorization'];
               kony.store.setItem('token', token);
               var ntf = new kony.mvc.Navigation("Form2");
               ntf.navigate();
           } else {
               kony.application.dismissLoadingScreen();
               kony.ui.Alert({
                   "alertType": constants.ALERT_TYPE_ERROR,
                   "alertTitle": "error",
                   "yesLabel": "OK",
                   "message": "username or password Incorrect!"
               }, {
                   "iconPosition": constants.ALERT_ICON_POSITION_LEFT
               });
           }
       }
   }

}

function IsJsonString(str) {
try {
JSON.parse(str);
} catch (e) {
return false;
}
return true;
}

Can anyone help me …

Thanks.

It could be that the certificate used by your https url is trusted on browser but not on mobile device.

Unless we have the actual URL being hit its difficult to check for any ssl errors happening

@Petew Alsop​ I had same issue, not while trying mobile app, but Responsive Web App.

It was working when viewed in visualizer but not in actual browser.

The issue was with CORS(Cross-Origin). Browsers only allow http-request from same domain.

Check if you have the same issue.