2016-06-14 73 views
0

我無法連接到任何使用下面的kony.net.httpRequest協議的服務器。我總是得到一個「服務器錯誤」的狀態文本。簡單kony.net.http請求不工作

function test(){ 
var xmlhttp = new kony.net.HttpRequest(); 
var url = "http://httpbin.org/get"; 
xmlhttp.open(constants.HTTP_METHOD_GET, url); 
xmlhttp.send(); 
xmlhttp.onReadyStateChange = function(){ sunsetCallback(xmlhttp) }; 
return; 
} 
function sunsetCallback(xmlhttp){ 
alert(xmlhttp.statusText); 
if (xmlhttp.responseType==constants.HTTP_RESPONSE_TYPE_DOCUMENT){ 
    sunrise.lblSunrise.text=xmlhttp.response; 
} 
sunrise.lblSunset.text="ayy lmao"; 
xmlhttp.suspend(); 
return; 
} 

任何幫助歡迎您! (我曾嘗試將onReadyStateChange行放在打開的上方和下方,但不管是否執行了sunsetCallback函數)。

回答

1

問題在於iOS不再允許應用程序在不編輯plist的情況下發送獲取請求。當我將請求更改爲https並將應用傳輸安全設置字典添加到plist時,問題已修復。

0

喲需要檢查請求的狀態之前做任何操作與響應。一旦狀態爲constants.HTTP_READY_STATE_DONE,您可以執行操作。

請檢查下面的工作代碼:

function searchData(){ 
    srchKey = frmMain.txtData.text; 
    var request = new kony.net.HttpRequest(); 
    request.onReadyStateChange=httpCallbackHandler; 
    request.open(constants.HTTP_METHOD_GET, "http://yoururlorapi.com/search/"+srchKey); 
    request.setRequestHeader("x-header-appsecret",appsec); //Our own data 
    request.send(); 
} 

function httpCallbackHandler(){ 
    if(this.readyState == constants.HTTP_READY_STATE_DONE){  
    //alert(JSON.stringify(this.response)); 
    frmSearchRes.segRes.setData(this.response.searchInfo); 
    frmSearchRes.show(); 
    } 
} 

希望這有助於!