dan dan - 1 year ago 102
JSON Question

Some character didn't post with Json Post - getting 500 reponse

I have prepared one API, and I want to send one specific data with json posting.

My code works fine during working with Fiddler or site side.

But the problem is why some character didn't send, when we use Android version as a client device.

For example:

string a="mn✈" // correct on any device (android,site,Fiddler,...)

string b="mn✉" //correct on any device except(android) //getting 500 reponse

String requestURL = Utils.SERVER_URL + "PostJsonFeatures";
HttpURLConnection conn = (HttpURLConnection) new URL(requestURL).openConnection();
conn.setRequestProperty("Content-Type", "application/json");
JSONObject postDataParams = new JSONObject();
postDataParams.put("Features", getAttributes());
postDataParams.put("productId", productId);
postDataParams.put("groupId", catId);
postDataParams.put("brandId", PrefManager.getInstance(context).getCompanyId());
postDataParams.put("languageId", PrefManager.getInstance(context).getLanguageApi());

DataOutputStream printout = new DataOutputStream(conn.getOutputStream ());
printout.flush ();
printout.close ();

Answer Source

You can decode to string and pass in url.

String parseString = URLDecoder.decode(URLEncoder.encode(myString, "UTF-8"), "ISO-8859-1");
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download