SocketException( Connection Timed Out ) Is Thrown When I Run My Android App On A Real Device
My android app needs to perform Http requests through HttpClient. i've tested on the emulator and it works fine. but when i do it on a real device with WIFI activated, sometimes A
Solution 1:
When ever I get this its when I get no data connection. Also check you have the right permissions cause that can do it to.
Solution 2:
Try using another method of sending HTTP request:
url = "http://<your URL>";
URL urlObj = new URL(url);
Log.d("DEBUG", "url=" + url);
URLConnection lu = urlObj.openConnection();
//optional - send parameters
String data = URLEncoder.encode("param", "UTF-8") + "=" + URLEncoder.encode(value, "UTF-8"); //optional - send parameters
// Send data
lu.setDoOutput(true);
OutputStreamWriter wr = new OutputStreamWriter(lu.getOutputStream());
wr.write(data);
wr.flush();
//end of "optional"
// Get the response
BufferedReader rd = new BufferedReader(new InputStreamReader(lu.getInputStream()));
String line = "", res = "";
while ((line = rd.readLine()) != null) {
res += line;
}
wr.flush();
wr.close();
Log.d("DEBUG", "res=" + res);
Post a Comment for "SocketException( Connection Timed Out ) Is Thrown When I Run My Android App On A Real Device"