Skip to content Skip to sidebar Skip to footer

Http Request To Password Protected Files

The php files on my server are password protect with htaccess. How can I make request to these files through my android app? I couldnt find any relevant answers with google search.

Solution 1:

Here you can find your answer:

Basic HTTP Authentication on Android

Basically:

HttpUriRequestrequest=newHttpGet(YOUR_URL); // Or HttpPost(), depends on your needsStringcredentials= YOUR_USERNAME + ":" + YOUR_PASSWORD;
Stringbase64EncodedCredentials= Base64.encodeToString(credentials.getBytes(), Base64.NO_WRAP);
request.addHeader("Authorization", "Basic " + base64EncodedCredentials);

HttpClienthttpclient=newDefaultHttpClient();
httpclient.execute(request);
// You'll need to handle the exceptions thrown by execute()

You can replace the last line with:

EDITED:

You can try someting like this:

try {
HttpResponseresponse= httpclient.execute(request);
    //this is the login response, logged so you can see it - just use the second part of the log for anything you want to do with the data

    Log.d("Login: Response", EntityUtils.toString(response.getEntity()));
} catch (IOException e) {
//if something went badly wrong
}

So you can view your response, maybe the problem is parsing the JSON.

Solution 2:

Assuming your PHP files are protected by HTTP Basic Authentication, you can request your php files using this special URL syntax:

http://validuser:validpassword@www.domain.com/validfile.php

Post a Comment for "Http Request To Password Protected Files"