我想從我的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>
誰能給我暗示哪裏出了問題。謝謝..
HTTP:/myserver.com:6718/cgi-bin目錄/ log.pl郵編= 你忘了'/'在URL的開頭 –
@VitoShadow真的說了些什麼。您的網址不正確,因此爲UnknownHostException。 –
@我更新了URL。這是正確的。在這裏複製時我被打亂了。 – typedefcoder2