hc-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Michael Becke <be...@u.washington.edu>
Subject Re: preemptive
Date Tue, 10 Jun 2003 02:48:36 GMT
Zulfi,

Please send a wire and trace log.  It is difficult to resolve these 
sort of problems without them.  Take a look at 
http://jakarta.apache.org/commons/httpclient/logging.html for details.

Mike

On Monday, June 9, 2003, at 06:44 PM, Zulfi Umrani wrote:

> Tried to use the Preemptive Authentication feature. Could not get it to
> work. I used the HttpState.setAuthenticationPreemptive(true); to set 
> the
> preemptive authentication ON. It still send the first request without
> the Authorization header. Code sample is below. Would like to know, how
> to set up the Pre-emptive Authentication.
>
> package test;
>
> import java.io.*;
> import java.net.URL;
>
> import org.apache.commons.httpclient.*;
> import org.apache.commons.httpclient.methods.*;
> import org.apache.commons.httpclient.auth.*;
> import org.apache.commons.httpclient.util.*;
>
> public class JCTest {
>     public static void main(String[] args) throws Exception {
> 	test0();
> 	test0();
> 	return;
>     }
>
>     public static void test0() throws Exception {
> 	System.out.println("running test0");
>
> 	String urlstr = "http://localhost:9999/services1/test";
> 	URL url = new URL(urlstr);
> 	
> 	HttpClient hc = new HttpClient();
> 	HttpState state = hc.getState();
> 	state.setAuthenticationPreemptive(true);
> 	state.setCredentials("", url.getHost(),
> 	    new UsernamePasswordCredentials("zulfi", "zulfi"));
>
> 	PostMethod post = new PostMethod(urlstr);
> 	post.setDoAuthentication(true);
>
> 	post.addRequestHeader("Connection", "Keep-Alive");
> 	post.addRequestHeader("Content-Length", ""+msg.length());
> 	post.addRequestHeader("Content-Type", "text/xml;
> charset=utf-8");
>
> 	InputStream reqis = new ByteArrayInputStream(msg.getBytes());
> 	
> 	post.setRequestBody(reqis);
>
> 	HostConfiguration hconfig = new HostConfiguration();
> 	hconfig.setHost(new URI(urlstr));
> 	
> 	hc.executeMethod(hconfig, post);
>
> 	System.out.println(post.getResponseBodyAsString());
> 	System.out.println();
> 	
>     }
>
>     private static String msg = "Text Message";
>
> }
>
>
> Thanks.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: 
> commons-httpclient-dev-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: 
> commons-httpclient-dev-help@jakarta.apache.org
>


Mime
View raw message