Reputation: 51
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) {
builder.append(line);
System.out.println("Linea recibida : " + line);
}
}
} catch (Exception e){
System.out.println("Primer catch");
e.printStackTrace();
}
return builder.toString();
}
Upvotes: 1
Views: 2576
Reputation: 130
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:
Upvotes: 2