(Android) Seems like my JSON query is getting double encode
I am getting some weird errors with my Android App. It appears that this code is double encoding the JSON string. What should be sent is ?{"email":"asdf@asdf.com","password":"asdf"} or ?%7B%22email%22:%22.....
what the server is seeing is %257B%2522email%2522:%2522 .... which means the server sees %7B%22email%22:%22 .....
This confuses the server.
Any ideas why this is happening?
Thank you for your help
//edited to define objects better
Code:
DefaultHttpClient c = new DefaultHttpClient();
if(cookies!=null)
c.setCookieStore(cookies);
JSONObject jso = new JSONObject():
if(loginNotLogout){
jso.put("email", "email@email.com");
jso.put("password", "PassW0RD");
}
URI u = null;
if(loginNotLogout)
u= new URI("HTTP","www.website.com","/UserService",jso.toString(),"");
else
u= new URI("HTTP","www.website.com","/UserService",jso.toString(),"");
HttpGet httpget = new HttpGet(u);
HttpResponse response = c.execute(http开发者_运维问答get);
ret.jsonString = EntityUtils.toString(response.getEntity());
what is userData
?
are you getting values from any EditText?
will using getText().toString()
with the text from EditText help?
As it turns out, dropping the "www." from the authority field in the URI constructor caused the address string to be encoded correctly.
I am no web expert, but if anyone can explain this I am all ears. or eyes in this case.
-- Andrew
精彩评论