我想從模擬器運行一個andriod應用程序,但每當我發送一個有效的url請求它顯示404作爲狀態碼。我有以下代碼。java httpclient返回404作爲響應代碼
如果我使用
http://10.0.2.2/api/ca/entry/?format=json&username=pragya
從模擬器瀏覽器,它返回的罰款。
HttpClient httpclient = new DefaultHttpClient();
HttpGet httppost = new HttpGet("http://10.0.2.2/api/ca/entry/?format=json&username=pragya");
try {
HttpResponse response = httpclient.execute(httppost);
Integer i =response.getStatusLine().getStatusCode();
Toast.makeText(HelloWorldActivity.this, i.toString(), Toast.LENGTH_SHORT).show();
}
編輯................ 清單文件是如下
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.andriod.test"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk android:minSdkVersion="10" />
<uses-permission android:name="android.permission.INTERNET" />
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name" >
<activity
android:name=".HelloWorldActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
也許下面的線程會幫助你:http://stackoverflow.com/questions/10867434/socketexception-connection-timed-out-is-thrown-when-i-run-my-android-app-on -a/10902080#10902080 – alfasin
'package =「com.andriod.test」'也許這個錯字會導致問題?請檢查它是否與您的課程名稱相匹配 – hage