i got issue with URL and getting null as response.I have also tried to Make it Encode but reponce is not getting as per expectation..
Here is my code :
try
{
String url = "http://mymemory.translated.net/api/get?q=Thanks&langpair=EN|KO" + query;
Log.i("URL", ">>>"+url);
JSONObject Responce = getJSONfromURL(url.toString());
Log.e("", "Responce"+Responce);
}
catch (Exception e) {}
Error Log:
10-12 20:13:35.411: INFO/URL(6844): >>>http://mymemory.translated.net/api/get?q=Thanks&langpair=EN|KO
10-12 20:13:35.531: ERROR/log_tag(6844): Error in http connection java.lang.IllegalArgumentException: Illegal character in query at index 59: http://mymemory.translated.net/api/get?q=Thanks&langpair=EN|KO
10-12 20:13:35.531: ERROR/log_tag(6844): Error converting result java.lang.NullPointerException
10-12 20:13:35.531: ERROR/log_tag(6844): Error parsing data org.json.JSONException: End of input at character 0 of
10-12 20:13:35.541: ERROR/(6844): Responcenull
After Encoding
URL Encode method apply..
String query = URLEncoder.encode("Thanks&langpair=EN|KO", "utf-8");
String url = "http://mymemory.translated.net/api/get?q=" + query;
Log.i("URL", ">>>"+url);
JSONObject Responce = getJSONfromURL(url.toString());
Log.e("", "Responce"+Responce);
Log ::
10-12 20:21:01.180: INFO/URL(7050): >>>http://mymemory.translated.net/api/get?q=Thanks%26langpair%3DEN%7CKO
10-12 20:21:01.710: ERROR/(7050): Responce{"responseData":{"translatedText":"INVALID LANGUAGE PAIR SPECIFIED. EXAMPLE: LANGPAIR=EN|IT USING 2 LETTER ISO OR RFC3066 LIKE ZH-CN. ALMOST ALL LANGUAGES SUPPORTED BUT SOME MAY HAVE NO CONTENT"},"matches":"","responseStatus":403,"responseDetails":"INVALID LANGUAGE PAIR SPECIFIED. EXAMPLE: LANGPAIR=EN|IT USING 2 LETTER ISO OR RFC3066 LIKE ZH-CN. ALMOST ALL LANGUAGES SUPPORTED BUT SOME MAY HAVE NO CONTENT"}
Don’t URLEncode the “=” in your query string. Essentially, you just want to urlEncode the values. So if your URL looked like this, it would work: