这是我的代码,它在模拟器中完美运行但有些原因,这个问题发生在真实设备上。
http connectionjava.net.UnknownHostException:my.url.com
中的错误
try{
HttpClient httpclient = new DefaultHttpClient();
HttpPost http = new HttpPost("http://my_url.com/folder/login.php");
http.setEntity(new UrlEncodedFormEntity(nameValuePairs));
HttpResponse response = httpclient.execute(httppost);
HttpEntity entity = response.getEntity();
is = entity.getContent();
}catch(Exception e){
Log.e("log_tag", "Error in http connection"+e.toString());
}
答案 0 :(得分:1)
Error in http connectionjava.net.UnknownHostException
为避免这种情况,请检查以下内容:
答案 1 :(得分:-2)
您的代码似乎很好 您能否请检查您是否错过了为您的设备授予互联网访问权限 您在 Android清单中设置的权限 添加以下权限,以帮助您魅力...
<uses-permission android:name="android.permission.INTERNET"></uses-permission>