1

我正在尝试从模拟器运行一个 andriod 应用程序,但是每当我发送一个有效的 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>
4

2 回答 2

2

尝试两件事一应该是解决方案

1 - 检查条目是否存在于清单中android.permission.INTERNET

2-尝试在手机本机浏览器中打开相同的

  • 2-a 如果打开就好了

    2-b 如果未打开,请在桌面浏览器中尝试该 url

于 2012-06-15T06:01:23.527 回答
0

确保服务器与您要连接的应用程序一起运行。 http 404 的更多信息

于 2012-06-15T06:11:46.107 回答