Wouter wrote:
> 
> 
> On Apr 30, 6:25 am, Jon Colverson <[email protected]> wrote:
>> On Apr 29, 6:06 pm, Wouter <[email protected]> wrote:
>>
>>> I cannot access my page! How can I do this?
>> Can you post your code?
>>
>> --
>> Jon
> 
> I have tried to do it with the normal HttpClient and now I have done
> it with the apache commons HttpClient:
> 
> public class httpTest extends Activity{
> 
> 
> 
>        private HttpClient httpClient = new HttpClient();
> 
>         @Override
>         public void onCreate(Bundle savedInstanceState)
>         {
>           super.onCreate(savedInstanceState);
>           retreiveProjects();
>         }
> 
>         private void retreiveProjects()
>         {
> 
> 
>                 httpClient.getParams().setBooleanParameter
> ( HttpClientParams.REJECT_RELATIVE_REDIRECT, false);
> 
>               httpClient.getParams().setBooleanParameter
> ( HttpClientParams.ALLOW_CIRCULAR_REDIRECTS, true); //true
> 
>               httpClient.getHostConfiguration().getParams().setParameter
> ("http..version", HttpVersion.HTTP_1_1);
> 
>               httpClient.getHostConfiguration().setHost("192.168.1.66",
> 3000, "http");
> 
>               HttpState initialState = new HttpState();
>               initialState.setCredentials(new AuthScope(AuthScope.ANY_HOST,
> AuthScope.ANY_PORT), new UsernamePasswordCredentials("wouter",
> "sleutel"));
> 
>               httpClient.setState(initialState);
> 
> 
>               httpClient.getState().setCredentials(
>                       new AuthScope(AuthScope.ANY_HOST, 3000, "realm"),
>                       new UsernamePasswordCredentials("wouter", "sleutel")
>                   );
> 
>               httpClient.getParams().setCookiePolicy
> (CookiePolicy.RFC_2109);
>               GetMethod getMethodInfoPage = new GetMethod("http://
> 192.168.1.66:3000/users.xml");
>               getMethodInfoPage.setDoAuthentication(true);
>                getMethodInfoPage.addRequestHeader("Accept", "image/gif,
> image/x-xbitmap, image/jpeg, image/pjpeg, application/x-shockwave-
> flash, application/vnd.ms-excel, application/vnd.ms-powerpoint,
> application/msword, */*");
> 
>                getMethodInfoPage.addRequestHeader("Accept-Encoding", "gzip,
> deflate");
> 
>                getMethodInfoPage.addRequestHeader("Accept-Language", "en-
> us");
> 
>                System.out.println("\n" + "About to make call for
> getMethodInfoPage connection attempt");
> 
>                int status;
>                try {
>                  httpClient.executeMethod(getMethodInfoPage);
> 
>                }
>                 catch (IOException ex2) {
>                         ex2.printStackTrace();
>                 }
> 
> 
> 
> 
> 
> 
>         }
> 
> I am trying to get a restful resource on my localhost! Do i have to
> use the ip from my localhost or am i doing something wrong?
> But whren it seems that it don't pass my username and password when I
> try to access it!
> Like i said i tried it with curl when passing my username and password
> and i got a successfull response!

When seeking assistance on Apache HttpClient, you are probably better
off asking the Apache HttpClient project.

That being said, what you appear to be attempting to do is "preemptive
HTTP authentication" (providing credentials initially, rather than
responding to a 401 Unauthorized response). HttpClient appears to be bad
at this.

If you visit:

http://commonsware.com/AndTutorials

and download the source code (link on that page), look at tutorial
17-HttpClient. There, I have logic using HttpClient that performs
preemptive HTTP authentication -- hacking in the HTTP authentication
header using Base64 encoding.

You may find URLConnection to be a better means of doing preemptive HTTP
authentication. For example, that is what the JTwitter JAR uses under
the covers, since Twitter requires preemptive HTTP authentication.

-- 
Mark Murphy (a Commons Guy)
http://commonsware.com | http://twitter.com/commonsguy

_The Busy Coder's Guide to Android Development_ Version 2.0 Available!

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to