0 down vote favorite

Hi, I used org.apache.http.auth and develop demo code samples like
this:

        DefaultHttpClient httpclient = new DefaultHttpClient();

    httpclient.getCredentialsProvider().setCredentials(
            new AuthScope("www.yemeksepeti.com", 80),
            new UsernamePasswordCredentials("*******", "*******"));

    BasicHttpContext localcontext = new BasicHttpContext();


    BasicScheme basicAuth = new BasicScheme();
    localcontext.setAttribute("preemptive-auth", basicAuth);

    // Add as the first request interceptor
    httpclient.addRequestInterceptor(new PreemptiveAuth(), 0);

    HttpHost targetHost = new HttpHost("www.yemeksepeti.com", 80,
"http");

    HttpGet httpget = new HttpGet("/YemeksepetiCatalogWebService/
CatalogExportMobile.asmx/Mobile_GetCities");


    String responseStr = "";

    HttpResponse response = httpclient.execute(targetHost, httpget,
localcontext);
    HttpEntity entity = response.getEntity();
    InputStream is2 = response.getEntity().getContent();
    BufferedInputStream bis2 = new BufferedInputStream(is2);

    ByteArrayBuffer baf2 = new ByteArrayBuffer(1000);

    int current = 0;

    while ((current = bis2.read()) != -1)
    {
        baf2.append((byte) current);
    }
    responseStr = new String(baf2.toByteArray());

    if (entity != null) {
        entity.consumeContent();
    }

    httpclient.getConnectionManager().shutdown();

and add a class :

 static class PreemptiveAuth implements HttpRequestInterceptor {

    public void process(
            final HttpRequest request,
            final HttpContext context) throws HttpException,
IOException {

        AuthState authState = (AuthState) context.getAttribute(
                ClientContext.TARGET_AUTH_STATE);

        // If no auth scheme avaialble yet, try to initialize it
preemptively
        if (authState.getAuthScheme() == null) {
            AuthScheme authScheme = (AuthScheme) context.getAttribute(
                    "preemptive-auth");
            CredentialsProvider credsProvider = (CredentialsProvider)
context.getAttribute(
                    ClientContext.CREDS_PROVIDER);
            HttpHost targetHost = (HttpHost) context.getAttribute(
                    ExecutionContext.HTTP_TARGET_HOST);
            if (authScheme != null) {
                Log.v("TANIMLAMA OZGE","target host" +
targetHost.getHostName() +" "+ targetHost.getPort());
                Credentials creds = credsProvider.getCredentials(
                        new AuthScope(
                                targetHost.getHostName(),
                                targetHost.getPort()));
                if (creds == null) {
                    throw new HttpException("No credentials for
preemptive authentication");
                }
                authState.setAuthScheme(authScheme);
                authState.setCredentials(creds);
            }
        }

    }

}

}

But it gives that messages; I couldn't solve the problem. Have you any
idea?

    Authentication error: basic authorization challenge expected, but
not found Default buffer size used in BufferedInputStream constructor.
It would be better to be explicit if an 8k buffer is required.

    You are not authorized to view this page
    You are not authorized to view this page
    You do not have permission to view this directory or page using
the credentials that you supplied because your Web browser is sending
a WWW-Authenticate header field that the Web server is not configured
to accept.

    Please try the following:

        * Contact the Web site administrator if you believe you should
be able to view this directory or page.
        * Click the Refresh button to try again with different
credentials.

    HTTP Error 401.2 - Unauthorized: Access is denied due to server
configuration.
    Internet Information Services (IIS)

    Technical Information (for support personnel)

        * Go to Microsoft Product Support Services and perform a title
search for the words HTTP and 401.
        * Open IIS Help, which is accessible in IIS Manager (inetmgr),
and search for topics titled About Security, Authentication, and About
Custom Error Messages.

Thanks

-- 
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