On Wed, 2010-12-01 at 10:49 +0200, Filiz Gökçe wrote:
> Hi,
> I have a service that gives xml data. But it didn't connect, I reseach all
> of documents on internet and you site, I develop my code on you site exampl=
> e
>
> I give the example of my code :
>
> protected InputStream getInputStream() {
> try {
> SchemeRegistry schemeRegistry =3D new SchemeRegistry();
>
> // http scheme
> schemeRegistry.register(new Scheme("http",
> PlainSocketFactory.
> getSocketFactory(), 80));
> // https scheme
> schemeRegistry.register(new Scheme("https", new EasySSLSocketFactory()=
> ,
> 443));
>
> params =3D new BasicHttpParams();
> params.setParameter(ConnManagerPNames.MAX_TOTAL_CONNECTIONS, 1);
> params.setParameter(ConnManagerPNames.MAX_CONNECTIONS_PER_ROUTE, new
> ConnPerRouteBean(1));
> params.setParameter(HttpProtocolParams.USE_EXPECT_CONTINUE, false);
> HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1);
> HttpProtocolParams.setContentCharset(params, "utf8");
>
> // ignore that the ssl cert is self signed
> CredentialsProvider credentialsProvider =3D new
> BasicCredentialsProvider();
> credentialsProvider.setCredentials(new AuthScope("www.yemeksepeti.com"=
> ,
> AuthScope.ANY_PORT),
> new UsernamePasswordCredentials("cs_basari", "bas0102ari"));
> clientConnectionManager =3D new ThreadSafeClientConnManager(params,
> schemeRegistry);
>
> context =3D new BasicHttpContext();
> context.setAttribute("http.auth.credentials-provider",
> credentialsProvider);
>
> System.out.println("----------------yemeksepetiandroid---------------------=
> --
> http://www.yemeksepeti.com/YemeksepetiCatalogWebService/CatalogExportMobile=
> .asmx/Mobile_GetCities?");
>
>
> DefaultHttpClient client =3D new
> DefaultHttpClient(clientConnectionManager, params);
> HttpGet get =3D new HttpGet("
> http://www.yemeksepeti.com/YemeksepetiCatalogWebService/CatalogExportMobile=
> .asmx/Mobile_GetCities?");
>
> HttpResponse response =3D client.execute(get, context);
> HttpEntity entity =3D response.getEntity();
> System.out.println(response.getStatusLine());
> if (entity !=3D null) {
> System.out.println("Response content length: " +
> entity.getContentLength());
> }
> return entity.getContent();
> } catch (IOException e) {
> throw new RuntimeException(e);
> }
> }
> static class PreemptiveAuth implements HttpRequestInterceptor {
>
> public void process(
> final HttpRequest request,
> final HttpContext context) throws HttpException, IOExceptio=
> n
> {
>
> AuthState authState =3D (AuthState) context.getAttribute(
> ClientContext.TARGET_AUTH_STATE);
>
> // If no auth scheme avaialble yet, try to initialize it
> preemptively
> if (authState.getAuthScheme() =3D=3D null) {
> AuthScheme authScheme =3D (AuthScheme) context.getAttribute=
> (
> "preemptive-auth");
> CredentialsProvider credsProvider =3D (CredentialsProvider)
> context.getAttribute(
> ClientContext.CREDS_PROVIDER);
> HttpHost targetHost =3D (HttpHost) context.getAttribute(
> ExecutionContext.HTTP_TARGET_HOST);
> if (authScheme !=3D null) {
> Credentials creds =3D credsProvider.getCredentials(
> new AuthScope(
> targetHost.getHostName(),
> targetHost.getPort()));
> if (creds =3D=3D null) {
> throw new HttpException("No credentials for
> preemptive authentication");
> }
> authState.setAuthScheme(authScheme);
> authState.setCredentials(creds);
> }
> }
>
> }
>
>
> }
>
>
>
> And it gives these error log:
>
> 11-30 16:41:08.902: WARN/etAuthenticationHandler(629): Authentication schem=
> e
> ntlm not supported
> 11-30 16:41:08.932: WARN/DefaultRequestDirector(629): Authentication error:
> Unable to respond to any of these challenges: {ntlm=3DWWW-Authenticate: NTL=
> M,
> negotiate=3DWWW-Authenticate: Negotiate}
> 11-30 16:41:08.952: INFO/System.out(629): HTTP/1.1 401 Unauthorized
> 11-30 16:41:08.952: INFO/System.out(629): Response content length: 1656
The version of HttpClient shipped with Android does not support NTLM
authentication out of the box
You can either following this guide [1] to add support for NTLM to the
existing version of HttpClient or upgrade to HttpClient 4.1-beta1 which
supports NTLM out of the box.
Hope this helps
Oleg
[1] http://hc.apache.org/httpcomponents-client-ga/ntlm.html
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]