NotSimon
NotSimon

Reputation: 1815

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 httpclient = 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!

Upvotes: 2

Views: 3495

Answers (3)

NotSimon
NotSimon

Reputation: 1815

I was using Post instead of Get, JCs answered it in the comments on my original question.

Upvotes: 1

rmcc
rmcc

Reputation: 783

Use this example to guide you to pass username password and credentials, instead of using the url.

Upvotes: 0

Jason Rogers
Jason Rogers

Reputation: 19344

Did you think of giving the internet permission?

<uses-permission android:name="android.permission.INTERNET"/>

Upvotes: 1

Related Questions