Android can't access a web server?
So I've got a little script set up on my server that says whether a user is log in able or not. When accessing the url http:server-url/username/password/ I would get a string returned called "correct" or "incorrect".
What I'm doing in my Android app is the following:
HttpClient h开发者_如何转开发ttpclient = new DefaultHttpClient();
String url = "http://server-url/"+usernameText+"/"+passwordHash+"/";
HttpPost httppost = new HttpPost(url);
ResponseHandler<String> handler = new BasicResponseHandler();
try {
String response = httpclient.execute(httppost, handler);
Log.e("logged in",response);
} catch (ClientProtocolException e) {
Log.e("clientprotocolexception",e.toString());
} catch (IOException e) {
Log.e("ioexception","error");
}
I'm getting an error:
04-29 14:31:15.728: ERROR/clientprotocolexception(9366): org.apache.http.client.HttpResponseException: FORBIDDEN
but the website itself works fine when I just access it through the browser? Are these some settings I have to set correctly somewhere on the server, or am I forgetting something in my code?
Thanks!
Did you think of giving the internet permission?
<uses-permission android:name="android.permission.INTERNET"/>
I was using Post instead of Get, JCs answered it in the comments on my original question.
Use this example to guide you to pass username password and credentials, instead of using the url.
精彩评论