Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-25698] Android: HTTP GET returns 500 internal server error while it's working fine on the iOS

GitHub Issuen/a
TypeBug
Priorityn/a
StatusOpen
ResolutionUnresolved
Affected Version/sRelease 5.1.1, Release 7.0.1
Fix Version/sn/a
Componentsn/a
Labelsn/a
ReporterKai Lu
AssigneeUnknown
Created2018-01-23T06:15:50.000+0000
Updated2018-02-28T19:55:37.000+0000

Description

It's a simple http Get API query, it failed on android but iOS works fine. The http POST however works on both android and iOS. This has been tested on SDK 7.0.1 and 5.1.1 Sample Code: var win = Ti.UI.createWindow({ backgroundColor : 'white', }); win.addEventListener("click", function(){ var url = "https://files.staging-trimbledata.com/api/directories"; var oHead = { "Authorization":"Bearer eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJhdWQiOlsiZmlsZXMiXSwiaXNzIjoiY2VjX2N3IiwiZXhwIjoxNTQ4MjIxODAzLCJzdWIiOiJ0cm1iLnNlcnZpY2VzLmF1dGgudjEifQ.fkAtBw2s0e3ub_4H_EJYZOGgLb1wl5XgJK3yvtl9wu26UcayV_pn5BytB-BI9cV5bE2O35Hl3ssC2tSPmLgQ56eQkBL4b6CpsJfKhtJR783dqkHMfWKbTjNvJGmWYH9DXRg8TKn5glR-Dqueg-7H5YQBfZin6bJOl4svf2Eu9gvQ9WAjKp6uYip0Mj_M-WtBfgXy_zmb2QFgOga4HyTxNaltf6GxrzgxtQfOBdkaX8V5wrfzKmKUYdj4rxLCi_--Fb2BQApM5fv2hdh4WppJ0Y0GCVmuBrMacIk4KooU7TMisC_no_xyT36bpHCz6t2DObY2TYZ1aKJD71nIT9_Vpg", "Content-Type":"application/json" }; var client = Ti.Network.createHTTPClient({ // function called when the response data is available onload : function(e) { Ti.API.info("Received text: " + this.responseText); alert('success'); }, // function called when an error occurs, including a timeout onerror : function(e) { Ti.API.info(e.error); alert('error'); }, timeout : 50000 // in milliseconds }); // Prepare the connection. client.open("GET", url); for(var key in oHead){ Ti.API.debug("set header: "+key); client.setRequestHeader(key, oHead[key]); } // Send the request. client.send(); }); win.open();

Comments

  1. Mostafizur Rahman 2018-01-23

    Hello [~kenjorai], Thanks for sharing with us. When we hit the [link](https://files.staging-trimbledata.com/api/directories) through browser it provides a HTTP [ERROR](https://s17.postimg.org/59f8nw5q7/Screen_Shot_2018-01-23_at_4.30.39_PM.png) .Can you please try using a valid url, test again and let us know. Best
  2. Kai Lu 2018-01-23

    Hi Mostafizur, This is a valid link, if you put it in a browser, it will give you a 401 error which means unauthorised access. You will need to put the Authorization header in the http GET request. To test it properly without Titanium, you will need to install POSTMAN or you can simply create a project and copy & paste my sample code. Regards
  3. Hans Knöchel 2018-01-23

    It works on Postman as well (even without the Content-Type). Looks valid to me, moving to TIMOB.

JSON Source