我正在尝试从我的服务器上的网页获取数据。但是,当我运行此代码时,它总是在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。我已尝试过不同的URL,但问题仍然存在。
Android Manifest文件就像:
<?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>
任何人都可以告诉我提示问题在哪里。感谢..
答案 0 :(得分: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>