本文介绍了Java的未知的主机异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图通过HTTP POST请求从我的Andr​​oid应用程序访问textalertapp.com。但我正在逐渐未知主机错误。任何人可以帮助我解决这个问题。

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

code是

  HttpClient的客户端=新DefaultHttpClient();
                字符串postURL =htt​​p://textalertapp.com/android$c$c/?api=AlertManager&method=getAlerts;
                HttpPost后=新HttpPost(postURL);

                名单<的NameValuePair> PARAMS =新的ArrayList<的NameValuePair>();
                params.add(新BasicNameValuePair(用户,短剑));
                params.add(新BasicNameValuePair(通,XYZ));
                UrlEn codedFormEntity ENT =新UrlEn codedFormEntity(参数,可以HTTP.UTF_8);
                post.setEntity(ENT);
                HTT presponse responsePOST = client.execute(后);
                HttpEntity resEntity = responsePOST.getEntity();
                如果(resEntity!= NULL){
                    Log.i(响应,EntityUtils.toString(resEntity));
                }
 

解决方案

 <使用-权限的Andr​​oid:名称=android.permission.INTERNET对>< /使用-许可&GT ;
 

我只是说这行清单文件。问题解决了。

I am trying to access textalertapp.com via HTTP Post request from my android application. But I am getting Unknown host error. Can anybody help me solve this issue.

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)

Code is

 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>

I just added this line in manifest file. Problem solved

这篇关于Java的未知的主机异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-26 06:14