I have tried to do it with the normal HttpClient and now I have done
it with the apache commons HttpClient:


On Apr 30, 6:25 am, Jon Colverson <jjc1...@gmail.com> wrote:
> On Apr 29, 6:06 pm, Wouter <wouterg...@gmail.com> wrote:
>
> > I cannot access my page! How can I do this?
>
> Can you post your code?
>
> --
> Jon

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();
                  }




               /* // create a thread-safe connection manager. Allows multiple
threaded requests from client
                ThreadSafeClientConnManager multiThreadedConnectionManager =
new ThreadSafeClientConnManager(httpParams, registry);
                httpClient = new DefaultHttpClient
(multiThreadedConnectionManager, httpParams);

                // we only support basic authentication
                BasicScheme basicScheme = new BasicScheme();
                AuthSchemeRegistry authRegistry = new AuthSchemeRegistry();
                authRegistry.register(basicScheme.getSchemeName(), new
BasicSchemeFactory());
                this.httpClient.setAuthSchemes(authRegistry);
                this.httpClient.setCredentialsProvider(new
BasicCredentialsProvider());

                this.httpClient.getCredentialsProvider().setCredentials(
                        new AuthScope(AuthScope.ANY_HOST,
                                AuthScope.ANY_PORT,
                                AuthScope.ANY_REALM,
                                AuthScope.ANY_SCHEME),
                        new UsernamePasswordCredentials("wouter",
"sleutel"));

                    String url = "http://192.168.1.66:3000/me";;
                    Log.i( "HTTPTEST", "performing get " + url );


                try {
                        HttpGet method = new HttpGet( new URI(url) );
                        HttpResponse response = httpClient.execute(method);
                } catch (URISyntaxException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                } catch (ClientProtocolException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                } catch (IOException e) {
                        // TODO Auto-generated catch block
                        e.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!

Hope you can help me!

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

Reply via email to