2012-06-15 44 views
0

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

也许下面的线程会帮助你:http://stackoverflow.com/questions/10867434/socketexception-connection-timed-out-is-thrown-when-i-run-my-android-app-on -a/10902080#10902080 – alfasin

+0

'package =“com.andriod.test”'也许这个错字会导致问题?请检查它是否与您的课程名称相匹配 – hage

回答

2

要做两件事情之一shuold是解决

1 - 检查条目有没有在明显android.permission.INTERNET

2 - 尝试在手机自带浏览器打开相同

  • 2-A,如果拿开,然后它的罚款

    2-B如果不拿开尝试在桌面浏览器,网址

+0

请检查编辑的问题 – hangman

+0

ohh gr8您已经进入清单...所以请让我们使用也知道关于2a和2b? –

+1

2-a)我已经尝试了它的模拟器本地浏览器,它应该返回浏览器中的json输出,但它提示我下载,但它不是404,它是200,因为url可从本机浏览器调用 2-b)浏览器使用http:// localhost/api/entry/...它运行良好 – hangman

相关问题