gpt4 book ai didi

Java 未知主机异常

转载 作者:IT老高 更新时间:2023-10-28 20:55:39 25 4
gpt4 key购买 nike

我正在尝试通过来 self 的 android 应用程序的 HTTP Post 请求访问 textalertapp.com。但我收到未知主机错误。谁能帮我解决这个问题。

12-13 01:30:16.058: WARN/System.err(473): java.net.UnknownHostException: textalertapp.com
12-13 01:30:16.088: WARN/System.err(473): at java.net.InetAddress.lookupHostByName(InetAddress.java:513)
12-13 01:30:16.088: WARN/System.err(473): at java.net.InetAddress.getAllByNameImpl(InetAddress.java:278)
12-13 01:30:16.088: WARN/System.err(473): at java.net.InetAddress.getAllByName(InetAddress.java:242)
12-13 01:30:16.088: WARN/System.err(473): at org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:136)
12-13 01:30:16.099: WARN/System.err(473): at org.apache.http.impl.conn.AbstractPoolEntry.open(AbstractPoolEntry.java:164)
12-13 01:30:16.099: WARN/System.err(473): at org.apache.http.impl.conn.AbstractPooledConnAdapter.open(AbstractPooledConnAdapter.java:119)
12-13 01:30:16.099: WARN/System.err(473): at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:348)
12-13 01:30:16.108: WARN/System.err(473): at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:555)
12-13 01:30:16.118: WARN/System.err(473): at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:487)
12-13 01:30:16.118: WARN/System.err(473): at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:465)
12-13 01:30:16.118: WARN/System.err(473): at com.textalert.alertCollection.getAlerts(alertCollection.java:46)
12-13 01:30:16.118: WARN/System.err(473): at com.textalert.alertsList$1.run(alertsList.java:81)
12-13 01:30:16.128: WARN/System.err(473): at java.lang.Thread.run(Thread.java:1096)

代码是

 HttpClient client = new DefaultHttpClient();
String postURL = "http://textalertapp.com/androidCode/?api=AlertManager&method=getAlerts";
HttpPost post = new HttpPost(postURL);

List<NameValuePair> params = new ArrayList<NameValuePair>();
params.add(new BasicNameValuePair("user", "kris"));
params.add(new BasicNameValuePair("pass", "xyz"));
UrlEncodedFormEntity ent = new UrlEncodedFormEntity(params,HTTP.UTF_8);
post.setEntity(ent);
HttpResponse responsePOST = client.execute(post);
HttpEntity resEntity = responsePOST.getEntity();
if (resEntity != null) {
Log.i("RESPONSE",EntityUtils.toString(resEntity));
}

最佳答案

<uses-permission android:name="android.permission.INTERNET"></uses-permission>

我刚刚在 list 文件中添加了这一行。问题解决了

关于Java 未知主机异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4427487/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com