मैं दूरस्थ सर्वर से प्रतिक्रिया प्राप्त करने का प्रयास कर रहा हूं। यहाँ मेरी कोड है:एंड्रॉइड java.lang.IllegalArgumentException HttpGet
private static String baseRequestUrl = "http://www.pappico.ru/promo.php?action=";
@SuppressWarnings("deprecation")
public String executeRequest(String url) {
String res = "";
HttpClient httpClient = new DefaultHttpClient();
HttpResponse response;
try {
//url = URLEncoder.encode(url, "UTF-8");
HttpGet httpGet = new HttpGet(url);
response = httpClient.execute(httpGet);
Log.d("MAPOFRUSSIA", response.getStatusLine().toString());
HttpEntity entity = response.getEntity();
if (entity != null) {
InputStream inStream = entity.getContent();
res = streamToString(inStream);
inStream.close();
}
} catch (Exception e) {
e.printStackTrace();
}
return res;
}
public String registerUser(int userId, String userName) {
String res = "";
String request = baseRequestUrl + "RegisterUser¶ms={\"userId\":" +
userId + ",\"userName\":\"" + userName + "\"}";
res = executeRequest(request);
return res;
}
और मैं लाइन HttpGet httpGet = new HttpGet(url)
में निम्न अपवाद हो रही है: http://www.pappico.ru/promo.php?action=RegisterUser¶ms= { "उपयोगकर्ता id": सूचकांक 59 पर क्वेरी में अवैध अक्षर:
java.lang.IllegalArgumentException: 1, "उपयोगकर्ता नाम": "Юрий Клинских"}
'{' चरित्र के साथ क्या गलत है? मैं पहले से ही इस अपवाद के बारे में कुछ पोस्ट पढ़ सकते हैं और एक समाधान मिला, लेकिन इस समाधान एक और अपवाद का कारण बनता है: अगर मैं लाइन url = URLEncoder.encode(url, "UTF-8");
uncommet यह इस तरह अपवाद के साथ लाइन response = httpClient.execute(httpGet);
पर craches:
java.lang.IllegalStateException: लक्ष्य मेजबान नहीं करना चाहिए शून्य हो, या पैरामीटर में सेट करें। योजना = अशक्त, मेजबान = अशक्त, पथ = http://www.pappico.ru/promo.php?action=RegisterUser¶ms= { "उपयोगकर्ता id": 1, "उपयोगकर्ता नाम": "Юрий + Клинских"}
क्या मैं इसे काम करने के लिए क्या करना चाहिए पता नहीं है। किसी भी मदद की सराहना की जाएगी :)
तो करो और लाइन प्रतिक्रिया में अपवाद android.os.NetworkOnMainThreadException मिल = httpClient.execute (httpGet); ' – konunger
ऐसा लगता है कि यह मेरी गलती है - मैं यूआई थ्रेड से नेटवर्क के साथ काम कर रहा हूं)) – konunger