I'm building a simple Web Service in Spring and accessing it from Android.

My web service works fine from my browser, and from the Android Emulator browser. But from my Android App, I get 403 error.

My App has Internet Permision.

This is my code:

protected String doInBackground(String... urls){

    String u = urls[0];
    HttpClient httpclient = new DefaultHttpClient();
    StringBuilder builder = new StringBuilder();
    HttpPost httppost = new HttpPost(u);
    System.out.println("URL: " + u);

    try { 
        HttpResponse respuesta = httpclient.execute(httppost);
        StatusLine statusLine = respuesta.getStatusLine();
        int statusCode = statusLine.getStatusCode();
        System.out.println("Status : " + statusCode);

        if (statusCode == 200){
            HttpEntity entity = respuesta.getEntity();
            InputStream contenido = entity.getContent();
            BufferedReader reader = new BufferedReader(new InputStreamReader(contenido));

            String line;
            while ((line = reader.readLine()) != null) {
                System.out.println("Linea recibida : " + line);
    } catch (Exception e){
         System.out.println("Primer catch");

    return builder.toString();

1 Answers

Shakeeb Manjeri On

A 403 response indicates that the host or software you're connecting with isn't allowed to access the web service. Reasons for this might be:

  • The remote host you are is being blocked by a firewall
  • You've reached the limit of calls to the web service and they are blocking any further connections
  • You are sending credentials for authentication but the account is banned/disabled
  • The user-agent or some other header in your request is causing the service to reject the connection. Perhaps a missing header?