我想从模拟器运行一个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