【发布时间】:2012-06-12 00:37:22
【问题描述】:
在测试应用程序时,我不断收到仅在一台设备上偶尔出现的错误:GT-I9100(欧洲)三星 Galaxy S II。这些错误不会出现在任何其他设备上,即使是 SPH-D710 (Sprint) Samsung Galaxy S II。
应用使用的 URL 不会改变。它们与我可以在网络浏览器中输入的内容相同,或者与应用程序的 iOS 和桌面版本使用的相同。但有时它们会抛出 UnknownHostException,有时不会。
这是我正在使用的代码的经过严格清理的版本:
AndroidHttpClient client = AndroidHttpClient.newInstance(activity.getString(R.string.user_agent));
HttpPost httpPost = new HttpPost("http://" + subdomainId + ".website.com/doSomething.aspx");
try {
// Add your data
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
nameValuePairs.add(new BasicNameValuePair("parameter1", value1));
nameValuePairs.add(new BasicNameValuePair("parameter2", value2));
httpPost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
// Execute HTTP Post Request
HttpContext httpContext = new BasicHttpContext();
HttpResponse response = client.execute(httpPost, httpContext);
... ...
三星 Galaxy S II 是否有任何可能导致此问题的怪癖?它运行的是 Android 2.3.6。
【问题讨论】:
-
我在 ACRA 崩溃报告中看到了另一个示例,该报告针对在 Droid Razr 上运行的不同应用程序。该代码使用了 androidHttpClient.execute(httpPost)。硬编码的 URL 完全有效,但抛出了 UnknownHostException
-
设备没有网络连接时会不会出现UnknownHostException?
-
互联网连接不稳定(甚至不存在)可能导致 UnknownHostException。
-
问题很可能是不稳定的 dns 服务器,而不是连接本身。
标签: android httpclient