On 26/08/2003 2:27 AM, "Yue Luo" <[EMAIL PROTECTED]> wrote:
> Hi, > I want to do the following: > 1. The main thread/conneciton logins to a web site. It is a post > request like a online banking login, not HTTP authentication. The > server will return a cookie containing session id. > 2. Then the main thread creates two simultaneous threads to create two > connections to send two queries to the web site. Of course the cookie > needs to be sent with the get request. > > My questions are: > 1. Can the two subsequent threads/connections use the HttpState from the > main thread/connection directly? Or, should I clone two HttpState for > the two sub-threads? Does the clone() method of HttpState work properly? Yes, you should use 1 instance of HttpClient and make sure you are using the MultiThreadedHttpConnectionManager. So something like: HttpClient client = new HttpClient(new MultiThreadedHttpConnectionManager()); PostMethod login = new PostMethod(...); client.execute(login); login.releaseConnection(); Create as many threads as you like to do something like: GetMethod get = new GetMethod(...); client.execute(get); get.releaseConnection(); You should probably take a look at the multithreading guide: http://jakarta.apache.org/commons/httpclient/threading.html > 2. Do HttpState.addCookies() and HttpState.getCookies() create COPIES > of the cookies or work on the cookie objects directly? > > 3. This question is somewhat related to the above one. > client.executeMethod(method1); > Cookies[] cookie1=state.getState().getCooies(); > client.executeMethod(method2); > Cookies[] cookie2=state.getState().getCooies(); > If the server changes some cookies in the second method, will the cookie > objects in cookie1[] be changed? On this I couldn't be entirely certain and don't have time to analyse the code right now, though you could certainly do it yourself or even easier, just test it and find out. :) > Yue Regards, Adrian Sutton. ---------------------------------------------- Intencha "tomorrow's technology today" Ph: 38478913 0422236329 Suite 8/29 Oatland Crescent Holland Park West 4121 Australia QLD www.intencha.com --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]