java - HTTP/1.1 401 Authorization Required with HttpClient 4.1.1 -


updated code:- using ssl, still getting same error.. 

i trying open uri

https://some-host/a/getmeta?id=10  (this url passed proxi.jsp page) 

and proxi.jsp page, , getting error http/1.1 401 authorization required , when passing credentials too. why happening so.. , site use siteminder.

    <%@ page language="java" import=" org.apache.http.httpentity, org.apache.http.httpresponse, org.apache.http.auth.authscope, org.apache.http.auth.usernamepasswordcredentials, org.apache.http.client.methods.httppost, org.apache.http.client.methods.httpget, org.apache.http.impl.client.defaulthttpclient, org.apache.http.util.entityutils, java.io.inputstream, java.io.inputstreamreader, java.io.bufferedreader, java.security.keystore, java.io.fileinputstream, java.io.file, org.apache.http.conn.ssl.sslsocketfactory, org.apache.http.conn.scheme.scheme, javax.net.ssl.hostnameverifier, org.apache.http.impl.conn.singleclientconnmanager, javax.net.ssl.httpsurlconnection, org.apache.http.conn.scheme.schemeregistry, javax.net.ssl.sslcontext, java.security.cert.x509certificate, javax.net.ssl.x509trustmanager, javax.net.ssl.trustmanager, org.apache.http.conn.clientconnectionmanager, java.security.cert.certificateexception, org.apache.http.conn.scheme.scheme" contenttype="text/html; charset=iso-8859-1" pageencoding="iso-8859-1"%>      <%     string a_url = request.getparameter( "url" ) ;      defaulthttpclient httpclient = new defaulthttpclient();     try {         httpclient.getcredentialsprovider().setcredentials(                 new authscope(authscope.any_host, authscope.any_port, "realm"),                 new usernamepasswordcredentials("test", "pass"));           keystore truststore  = keystore.getinstance(keystore.getdefaulttype());         //fileinputstream instream = new fileinputstream(new file("my.keystore"));         inputstream instream = thread.currentthread().getcontextclassloader().getresourceasstream("my.keystore");         try {             truststore.load(instream, "nopassword".tochararray());         } {             try { instream.close(); } catch (exception ignore) {}         }     /*          sslsocketfactory socketfactory = new sslsocketfactory(truststore);         scheme sch = new scheme("https", 443, socketfactory);         httpclient.getconnectionmanager().getschemeregistry().register(sch);         */            sslcontext ctx = sslcontext.getinstance("tls");         x509trustmanager tm = new x509trustmanager() {          public void checkclienttrusted(x509certificate[] xcs, string string) throws certificateexception {         }          public void checkservertrusted(x509certificate[] xcs, string string) throws certificateexception {         }          public x509certificate[] getacceptedissuers() {         return null;         }         };         ctx.init(null, new trustmanager[]{tm}, null);         sslsocketfactory ssf = new sslsocketfactory(ctx);         ssf.sethostnameverifier(sslsocketfactory.allow_all_hostname_verifier);         clientconnectionmanager ccm = httpclient.getconnectionmanager();         schemeregistry sr = ccm.getschemeregistry();         sr.register(new scheme("https", ssf, 443));             httpget httpget = new httpget(a_url);            system.out.println("executing request" + httpget.getrequestline());         httpresponse res = httpclient.execute(httpget);          httpentity entity = res.getentity();          system.out.println("----------------------------------------");         system.out.println(res.getstatusline());         if (entity != null) {              system.out.println("response content length: " + entity.getcontentlength());             inputstream input = entity.getcontent();             bufferedreader reader = new bufferedreader(new inputstreamreader(input));             string ln = "";             while((ln = reader.readline()) != null) {                 out.println("during - " + ln);             }             entity.consumecontent();         }         entityutils.consume(entity);     }      catch (throwable t) {         stacktraceelement[] x = t.getstacktrace();         for(int k=0;k<x.length;k++) {             out.println(x[k].tostring());         }         //out.println();         t.printstacktrace();     }       {         // when httpclient instance no longer needed,         // shut down connection manager ensure         // immediate deallocation of system resources         httpclient.getconnectionmanager().shutdown();     }       %> 

you accessing secure site don't see ssl handling in httpclient code. can have @ this page , try out in standalone client after filling in appropriate gaps?


Comments

Popular posts from this blog

c# - SharpSVN - How to get the previous revision? -

c++ - Is it possible to compile a VST on linux? -

url - Querystring manipulation of email Address in PHP -