Steps to reproduce
Create xhr that pings an endpoint that returns 'true' or 'false
function doit() {
var xhr = Ti.Network.createHTTPClient({
onload: function onLoad(e) {
alert("Received: Status = " + e.status + ", Value = " + e.responseText);
},
onerror: function onError(e) {
alert("Error: Status = " + e.status + ", Value = " + e.responseText);
}
});
xhr.open("GET", "https://13b6379a34068a7bb6c483d30f362f550675a41c.cloudapp-enterprise.appcelerator.com/t");
xhr.send();
}
Error generated
[ERROR] TiHTTPClient: (TiHttpClient-1) [3054,3054] HTTP Error (java.lang.NullPointerException): Attempt to invoke virtual method 'java.lang.String[] java.lang.String.split(java.lang.String)' on a null object reference
[ERROR] TiHTTPClient: java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String[] java.lang.String.split(java.lang.String)' on a null object reference
[ERROR] TiHTTPClient: at ti.modules.titanium.network.TiHTTPClient.handleResponse(TiHTTPClient.java:195)
[ERROR] TiHTTPClient: at ti.modules.titanium.network.TiHTTPClient.access$1200(TiHTTPClient.java:84)
[ERROR] TiHTTPClient: at ti.modules.titanium.network.TiHTTPClient$ClientRunnable.run(TiHTTPClient.java:1194)
[ERROR] TiHTTPClient: at java.lang.Thread.run(Thread.java:818)
Endpoint
function t(req, res){
res.end((((new Date()).getTime() & 1) == 1).toString());
}
thanks [~msamah]
Resolving issue as
Won't Fix
Reason being the endpoint is not being detected as there is no headerContent-Type
. iOS and Android behaviour are the same. HTTP protocols docs https://tools.ietf.org/html/rfc7231#section-3.1.1.5 {quote} A sender that generates a message containing a payload body SHOULD generate a Content-Type header field in that message unless the intended media type of the enclosed representation is unknown to the sender. If a Content-Type header field is not present, the recipient MAY either assume a media type of "application/octet-stream" ([RFC2046], Section 4.5.1) or examine the data to determine its type. {quote} Thus the endpoint should set the header for iOS and Android client to get the proper payload.Will look into this further.
Please run this code. This code will make it work.
Resolving this as invalid as the code above will make it work.
Also, you can run
appc ti sdk install -d -b 5_0_X
to get the branch 5.0.3 which contains 5.0.2.GA with the fixes to the first error issue.