我正在尝试从仿真器运行anriod应用程序,但是每当我发送有效的url请求时,它就会将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>
最佳答案
尝试两件事一解决
1-检查清单清单android.permission.INTERNET
中是否存在
2-尝试在手机本机浏览器中打开相同的内容
2-a如果打开就可以了
2-b如果无法打开,请尝试在桌面浏览器中使用该网址