java - apache httpclient doesn't set basic authentication credentials -
have @ following code:
defaulthttpclient http = new defaulthttpclient(); http.getcredentialsprovider().setcredentials( new authscope(authscope.any_host, authscope.any_port), new usernamepasswordcredentials( configuration.username, configuration.developerkey ) ); httppost post = new httppost(strurl); stringentity entity = new stringentity( ac.toxmlstring() ); entity.setcontenttype("text/xml"); post.setentity( entity ); org.apache.http.httpresponse response = http.execute( post );
it produces no errors. response server "no authorization header". checking request wireshark unveils there indeed no basic authentication set.
how possible?
okay, default basic authentication turned off. however, enabling far complicated (link) . therefore 1 can use code, works fine:
defaulthttpclient http = new defaulthttpclient(); httppost post = new httppost(strurl); usernamepasswordcredentials creds = new usernamepasswordcredentials( configuration.username, configuration.developerkey); post.addheader( basicscheme.authenticate(creds,"us-ascii",false) ); stringentity entity = new stringentity( ac.toxmlstring() ); entity.setcontenttype("text/xml"); post.setentity( entity ); org.apache.http.httpresponse response = http.execute( post );
Comments
Post a Comment