2011-11-15 107 views
1

我想从我的server.However网页获取数据时,我在httpClient.execute运行这段代码它总是失败()未知的主机异常

String flixURL=("http://myserver.com:6718/cgi-bin/log.pl?zip=" + zippy);    
Toast.makeText(getBaseContext(),flixURL,5).show(); 

DefaultHttpClient httpClient = new DefaultHttpClient(); 
HttpGet httpGet = new HttpGet(flixURL); 
ResponseHandler<String> resHandler = new BasicResponseHandler(); 
System.out.println("resHandler"+resHandler); 

try {     
String page = httpClient.execute(httpGet, resHandler);      
System.out.println("page"+page); 
} 
catch (ClientProtocolException e) 
{ 
e.printStackTrace();System.out.println(e); 
} 
catch (IOException e) { 
e.printStackTrace();System.out.println(e); 
} 

调试器告诉我可能是UnknownHostException。我尝试过不同的网址,但问题仍然存在。

Android清单文件是这样的:

<?xml version="1.0" encoding="utf-8"?> 
<manifest xmlns:android="http://schemas.android.com/apk/res/android" 
    package="com.example.andtwi" 
    android:versionCode="1" 
    android:versionName="1.0" > 

    <uses-sdk android:minSdkVersion="8" /> 

    <application 
     android:icon="@drawable/ic_launcher" 
     android:label="@string/app_name" > 
     <activity 
      android:label="@string/app_name" 
      android:name=".AndTwitterActivity" > 
      <intent-filter > 
       <action android:name="android.intent.action.MAIN" /> 

       <category android:name="android.intent.category.LAUNCHER" /> 
      </intent-filter> 
     </activity> 
       <activity android:name=".screen2" android:label="Screen2"> 
     </activity> 
     <uses-permission android:name="android.permission.INTERNET" /> 

    </application> 

</manifest> 

谁能给我暗示哪里出了问题。谢谢..

+3

HTTP:/myserver.com:6718/cgi-bin目录/ log.pl邮编= 你忘了'/'在URL的开头 –

+0

@VitoShadow真的说了些什么。您的网址不正确,因此为UnknownHostException。 –

+0

@我更新了URL。这是正确的。在这里复制时我被打乱了。 – typedefcoder2

回答

5

移动此行

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

<application>标签:

<?xml version="1.0" encoding="utf-8"?> 
<manifest xmlns:android="http://schemas.android.com/apk/res/android" 
    package="com.example.andtwi" 
    android:versionCode="1" 
    android:versionName="1.0" > 

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

    <application 
     android:icon="@drawable/ic_launcher" 
     android:label="@string/app_name" > 
     <activity 
      android:label="@string/app_name" 
      android:name=".AndTwitterActivity" > 
      <intent-filter > 
       <action android:name="android.intent.action.MAIN" /> 

       <category android:name="android.intent.category.LAUNCHER" /> 
      </intent-filter> 
     </activity> 
       <activity android:name=".screen2" android:label="Screen2"> 
     </activity> 

    </application> 

</manifest> 
+0

Voila ...它工作...感谢LAS_Vegas ..嘿,你怎么知道我的冬季度假目的地:) 顺便说一句..你能解释为什么你问我要移出那些代码的代码...谢谢 – typedefcoder2

+0

这是一个常见的错误,当它们在里面时,权限不起作用:)有关详细信息,请参阅http://developer.android.com/guide/topics/manifest/manifest-intro.html。 – Caner