Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-24809] Android: HTTPClient - "onload" not dispatched

GitHub Issuen/a
TypeBug
PriorityMedium
StatusClosed
ResolutionFixed
Resolution Date2017-06-14T17:41:53.000+0000
Affected Version/sRelease 6.1.0
Fix Version/sRelease 6.1.1
Componentsn/a
Labelsn/a
Reportergianluca
AssigneeYordan Banev
Created2017-06-12T08:53:19.000+0000
Updated2017-06-15T19:02:16.000+0000

Description

When an instance of TiHTTPClient is reused for another request with a file passed in the data the contentLength is not calculated properly. The request passes but the "onLoad" event is not dispatched. *Test case*: Click "Get Photos", wait for the reponse, dismiss the alert, and then click "Upload photo" - the request finishes but the "onload" event listener is not called.
var window = Ti.UI.createWindow();
var buttonUpload = Ti.UI.createButton({title:"Upload", top:50});
var buttonGetPhotos = Ti.UI.createButton({title:"Get Photos", top: 110});
var xhr = Titanium.Network.createHTTPClient({timeout:5000});
 
var tempF = Ti.Filesystem.getFile(Ti.Filesystem.resourcesDirectory,"simpleTest.png");
Ti.API.info(tempF);
 
buttonUpload.addEventListener('click', function (e) {
    xhr.open("POST","https://requestb.in/zwfzmzzw");

    var data_to_send = {
        "file": tempF.read(),
    };
 
    xhr.onload = function () {(alert(this.responseText))};
    xhr.send(data_to_send);
});
 
buttonGetPhotos.addEventListener('click', function (e) {    
    xhr.open("POST","https://requestb.in/zwfzmzzw");

    var params = {
            id:46
    };
 
    xhr.onload = function (e) {alert(this.responseText)};
    xhr.send(params);
});
 
window.add(buttonGetPhotos);
window.add(buttonUpload);
window.open();
_Another instance of requestb.in may need to be created for testing._ *Console Log:*
E/TiHTTPClient: (TiHttpClient-2) [142,13649] HTTP Error (java.lang.IllegalStateException): state: 2
                java.lang.IllegalStateException: state: 2
                    at com.android.okhttp.internal.http.HttpConnection.readResponse(HttpConnection.java:186)
                    at com.android.okhttp.internal.http.HttpTransport.readResponseHeaders(HttpTransport.java:80)
                    at com.android.okhttp.internal.http.HttpEngine.readNetworkResponse(HttpEngine.java:906)
                    at com.android.okhttp.internal.http.HttpEngine.readResponse(HttpEngine.java:782)
                    at com.android.okhttp.internal.huc.HttpURLConnectionImpl.execute(HttpURLConnectionImpl.java:463)
                    at com.android.okhttp.internal.huc.HttpURLConnectionImpl.getResponse(HttpURLConnectionImpl.java:405)
                    at com.android.okhttp.internal.huc.HttpURLConnectionImpl.getResponseCode(HttpURLConnectionImpl.java:521)
                    at com.android.okhttp.internal.huc.DelegatingHttpsURLConnection.getResponseCode(DelegatingHttpsURLConnection.java:105)
                    at com.android.okhttp.internal.huc.HttpsURLConnectionImpl.getResponseCode(HttpsURLConnectionImpl.java)
                    at ti.modules.titanium.network.TiHTTPClient$ClientRunnable.run(TiHTTPClient.java:1231)
                    at java.lang.Thread.run(Thread.java:761)

Attachments

FileDateSize
simpleTest.png2017-06-12T08:54:34.000+00006826

Comments

  1. Yordan Banev 2017-06-12

    PR(master): https://github.com/appcelerator/titanium_mobile/pull/9139 PR(6_1_X): https://github.com/appcelerator/titanium_mobile/pull/9140
  2. Samir Mohammed 2017-06-15

    Verified in SDK Version 6.1.1.v20170614134051 and 6.2.0.v20170614131253. Test and other information can be found at: PR(master): https://github.com/appcelerator/titanium_mobile/pull/9139 PR(6_1_X): https://github.com/appcelerator/titanium_mobile/pull/9140

JSON Source