hc-httpclient-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Scott Mueller <sc...@appletree.com>
Subject Re: How do you set cookies on initial post in HttpClient?
Date Fri, 20 Feb 2009 22:42:17 GMT
By the way, this example code of setting cookies in HttpClient doesn't work
either:
http://svn.apache.org/repos/asf/httpcomponents/httpclient/trunk/module-client/src/examples/org/apache/http/examples/client/ClientCustomContext.java

I copied the code there like this:
        DefaultHttpClient client = new DefaultHttpClient();
        CookieStore cookieStore = new BasicCookieStore();
        cookieStore.addCookie(new BasicClientCookie("JSESSIONID",
getParameter("session")));
        HttpContext context = new BasicHttpContext();
        context.setAttribute(ClientContext.COOKIE_STORE, cookieStore);
        client.execute(post, context);

Again, no cookies are specified on the http post.  All I want to do is
attach the applet to the same session as the browser.  Is there a better way
to do this?  Are cookies functional in HttpClient beta 2?

On Fri, Feb 20, 2009 at 1:50 PM, Scott Mueller <scott@appletree.com> wrote:

> I tried to add cookies like this, but no cookies are set as can be seen by
> the actual http post:
> DefaultHttpClient client = new DefaultHttpClient();
> client.getCookieStore().addCookie(new BasicClientCookie("JSESSIONID",
> getParameter("session")));
>
>
> POST /test/edit/image/upload_downloading_image HTTP/1.1
> Content-Length: 37135
> Content-Type: multipart/form-data;
> boundary=BBr9sC_KF9cYDun21feBJ8ZYwyBBkTWBT-Vfbo
> Host: 192.168.1.6:8080
> Connection: Keep-Alive
> User-Agent: Apache-HttpClient/4.0-beta2 (java 1.5)
> Expect: 100-Continue
>
> HTTP/1.1 100 Continue
>
> --BBr9sC_KF9cYDun21feBJ8ZYwyBBkTWBT-Vfbo
> Content-Disposition: form-data; name="id"
> Content-Type: text/plain; charset=windows-1252
> Content-Transfer-Encoding: 8bit
>
> 4
> --BBr9sC_KF9cYDun21feBJ8ZYwyBBkTWBT-Vfbo
> Content-Disposition: form-data; name="file"; filename="Scott_Ken.jpg"
> Content-Type: application/octet-stream
> Content-Transfer-Encoding: binary
>
>
> --
> Scott Mueller
> http://www.appletree.com
> AppleTree - Solve the Puzzle
>



-- 
Scott Mueller
http://www.appletree.com
AppleTree - Solve the Puzzle

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message