Application type: mobile Titanium SDK: 3.1.2.GA Platform & version: iOS 6.1 Device: iOS simulator and device Host Operating System: OSX 10.8.4
i have been debugging an HTTPClient problem on iOS for over a day now but with no luck. i have HTTPClient call that returns a json string from a java servlet. when executed, the request reaches the server normally but when printing the data to the response output stream i get "A connection failure occurred" error. its like a one way communication. the returned json string is valid and i even tried to use "text/plain" as a response header Content-Type but still with no luck. All works well on android. any ideas what might be the problem???
Client:
var isLoggedInXhr = Titanium.Network.createHTTPClient({ //enableKeepAlive : true, //timeout : 60000 }); isLoggedInXhr.onload = function() { var jsonObj = JSON.parse(this.responseText); if (!jsonObj.error) { if (jsonObj.isUserAuthenticated) { var Navigator = require('ui/common/Navigator'); var navInst = Navigator.getInstance(); navInst.setLoggedIn(true); navInst.init(); } else { var Navigator = require('ui/common/Navigator'); var navInst = Navigator.getInstance(); navInst.setLoggedIn(false); navInst.init(); } } //alert(this.responseText); }; isLoggedInXhr.onerror = function(e) { alert(e.error); }; Ti.API.info(Ti.App.Properties.getString('remoteServlet')); isLoggedInXhr.open("POST", Ti.App.Properties.getString('remoteServlet')); isLoggedInXhr = Cookies.setupHttpClient(isLoggedInXhr); isLoggedInXhr.send({ "action" : "getCurrentLoggedInUser" });the
Cookies.setupHttpClient(isLoggedInXhr);
sets header CookiesCookies.setupHttpClient = function(client) { if (Utils.isAndriod) { var header = "language=" + language + "; countryCode=" + countryCode + "; countryId=" + countryId; if (sessionId != null) header += "; JSESSIONID=" + sessionId; client.setRequestHeader("Cookie", header); } else { client.setRequestHeader("Cookie", "language=" + language); client.setRequestHeader("Cookie", "countryCode=" + countryCode); client.setRequestHeader("Cookie", "countryId=" + countryId); if (sessionId != null) client.setRequestHeader("Cookie", "JSESSIONID=" + sessionId); } return client; };
Server (servlet):
public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { String json = ""; String action = request.getParameter("action"); if (action != null) { if (action.equals("getCurrentLoggedInUser")) { json = getCurrentLoggedInUser(); } } response.setContentType("application/json"); response.setHeader("Content-Type", "application/json"); response.setCharacterEncoding("UTF-8"); ServletOutputStream out = response.getOutputStream(); out.print(json); out.flush(); out.close(); }