Hello!
I am developing an android app with the 1.7.0.RC1 Titanium SDK. Now i try to realise a http post request. The post request should submit text from a textarea. The text can contain espacially characters.
My code looks like this:
var url = "http://myTestURL.de/mobile/feedback"; var xhr = Titanium.Network.createHTTPClient(); xhr.onreadystatechange = function() { if (xhr.readyState == 4 || xhr.status == 200) { var toast = Titanium.UI.createNotification({ duration: 3000, message: "Successfully send msg." }); toast.show(); } } xhr.onerror = function(e) { Ti.API.info('Error:' + e.error); var toast = Titanium.UI.createNotification({ duration: 3000, message: "An Error occured." }); toast.show(); }; xhr.setTimeout(20000); xhr.open("POST", url); xhr.setRequestHeader("User-Agent",Titanium.userAgent); xhr.send(emailJsonData)The variable 'emailJsonData', which is being used for xhr.send(), contains a string.
var emailJsonData = "json={email:" + emailadress + ",comment:" + textareaContent + "}";And textareaContent contains espacial characters like such ,.@#$%&*-+()?/;:'"!~`|•??÷×{}][=_^°€¢£¥™®©¶\<>…„
Now, when i try to submit the text i get this error:
D/TiHttpClient( 1568): (kroll$1: app://app.js) [6,250686] Setting ready state to 1 I/TiAPI ( 1568): (kroll$1: app://app.js) [17,250703] SEND DATA: json={email:'test@test.de',comment:'test,.@#$%&*-+()?/;:'"!~`|•??÷×{}][=_^°€¢£¥™®©¶\<>…„',app_Version:'1.0'} I/TiAPI ( 1568): (kroll$1: app://app.js) [2,250705] JSON PARSED SUCCESSFULLY!!! I/TiAPI ( 1568): (kroll$1: app://app.js) [1,250706] email undefined D/TiHttpClient( 1568): (TiHttpClient-2) [233,250939] Setting ready state to 2 D/TiHttpClient( 1568): (TiHttpClient-2) [7,250946] Setting ready state to 3 D/TiHttpClient( 1568): (TiHttpClient-2) [12,250958] clearing the expired and idle connections W/IdleConnectionHandler( 1568): Removing a connection that never existed! E/TiHttpClient( 1568): (TiHttpClient-2) [12,250970] HTTP Error (org.apache.http.client.HttpResponseException): Internal Server Error E/TiHttpClient( 1568): org.apache.http.client.HttpResponseException: Internal Server Error E/TiHttpClient( 1568): at ti.modules.titanium.network.TiHTTPClient$LocalResponseHandler.handleResponse(TiHTTPClient.java:210) E/TiHttpClient( 1568): at ti.modules.titanium.network.TiHTTPClient$LocalResponseHandler.handleResponse(TiHTTPClient.java:170) E/TiHttpClient( 1568): at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:657) E/TiHttpClient( 1568): at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:637) E/TiHttpClient( 1568): at ti.modules.titanium.network.TiHTTPClient$ClientRunnable.run(TiHTTPClient.java:1016) E/TiHttpClient( 1568): at java.lang.Thread.run(Thread.java:1096) I/TiHttpClient( 1568): (TiHttpClient-2) [12,250982] Sending error Internal Server Error I/TiAPI ( 1568): (kroll$1: app://app.js) [3,250985] Error:Internal Server Error I/NotificationService( 53): enqueueToast pkg=de.eves callback=android.app.ITransientNotification$Stub$Proxy@43da2ac8 duration=3000 D/dalvikvm( 53): threadid=15: bogus mon 1+0>0; adjustingSo, can anybody tell me, how to submit espacial characters within a http post request??? I have tried to escape the textarea-text with a backslash, but it didnt work. I have found out, that most problems occure with this & + " ; ' characters.
Greets, Jonas