You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@commons.apache.org by Nate <nm...@charter.net> on 2003/06/26 15:20:46 UTC

HTTPClient

----- Original Message ----- 
From: "Nate" <nm...@charter.net>
To: <co...@jakarta.apache.org>
Sent: Thursday, June 26, 2003 8:10 AM


> I have a question for anybody using the HttpClient component.  Is there
> anything in particular that has to be done to enable cookies?  I have
> already set the policy (tried all 3) in the HttpState that is used by the
> client, but the site I am attempting to communicate with still thinks
> cookies are turned off.
> 

Re: HTTPClient

Posted by Nate <nm...@charter.net>.
Ed,

    Thanks for the advice, I solved the problem yesterday.  It was an IO
(idiot operator) error ;-).  I was accidentally sending some incorrect data
in my query string, and that caused the server to not set the cookie like it
should.

--Nathan

----- Original Message -----
From: "Ed Ludke" <ed...@yahoo.com>
To: "Jakarta Commons Users List" <co...@jakarta.apache.org>
Sent: Friday, June 27, 2003 9:25 AM
Subject: Re: HTTPClient


> Nate,
>
> Hey, I'm no expert so I'm not replying to the forum with this but I have
played a little with the HttpClient component with mixed sucess.  I hate to
ask the obvious, but have you checked out the code samples?  There is one
they published within the last few months that was particularly helpful.
Here's the link in case you haven't already seen it:
>
>
http://cvs.apache.org/viewcvs/jakarta-commons/httpclient/src/examples/FormLo
ginDemo.java?rev=1.1&content-type=text/vnd.viewcvs-markup
>
> and here's the link to all their code samples:
>
> http://cvs.apache.org/viewcvs/jakarta-commons/httpclient/src/examples/
>
> The key for me was seeing that you had to manage redirects sort of
manually as seen in the example I pointed out.
>
> There was one other thing that I'm not very sure about (it's been a few
weeks since I've worked with this).  but, out of the things I tried to get
stuff working, it sticks in my mind as having helped.  It was to set the
headers to "emulate" one of the well known browsers.  I seem to recall that
the site I was trying to hit wasn't working right so I examined what I was
sending vs. what the browser sent, then I set everything (header stuff) to
the match what it was sending and I was able to get further along (still
having some other problems but definately made progress once I did that).
>
> Here's a snippet of what I did:
>
>
> PostMethod method = new PostMethod( aUrl );
>
> method.setUseExpectHeader( false );
>
> method.setFollowRedirects(true);
>
>
> method.setStrictMode(false);
>
> method.setRequestHeader(new Header("user-agent","Mozilla/4.0 (compatible;
MSIE 6.0; Windows NT 5.1)" ) );
>
> method.setRequestHeader( new Header( "accept", "*/*" ) );
>
> method.setRequestHeader( new Header( "accept-language", "en-us" ) );
>
> method.setRequestHeader( new Header( "accept-encoding", "gzip,
deflate" ) );
>
> method.setRequestHeader( new Header( "connection", "Keep-Alive" ) );
>
> method.setRequestHeader( new Header( "cache-control", "no-cache" ) );
>
>
>
> Hope this helps.  If it does, let me know and maybe I'll post something to
the mailing list.
>
> Ed
>
>
> Nate <nm...@charter.net> wrote:
>
> ----- Original Message -----
> From: "Nate"
> To:
> Sent: Thursday, June 26, 2003 8:10 AM
>
>
> > I have a question for anybody using the HttpClient component. Is there
> > anything in particular that has to be done to enable cookies? I have
> > already set the policy (tried all 3) in the HttpState that is used by
the
> > client, but the site I am attempting to communicate with still thinks
> > cookies are turned off.
> >
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: commons-user-help@jakarta.apache.org
>
>
> ---------------------------------
> Do you Yahoo!?
> SBC Yahoo! DSL - Now only $29.95 per month!


Re: HTTPClient

Posted by Ed Ludke <ed...@yahoo.com>.
doh! well I guess I _am_ replying to the forum with this - well I hope it helps _some_ so that I don't look like a _complete_ idiot . . .  sorry for the spam all.
 
Ed

Ed Ludke <ed...@yahoo.com> wrote:
Nate,

Hey, I'm no expert so I'm not replying to the forum with this but I have played a little with the HttpClient component with mixed sucess. I hate to ask the obvious, but have you checked out the code samples? There is one they published within the last few months that was particularly helpful. Here's the link in case you haven't already seen it:

http://cvs.apache.org/viewcvs/jakarta-commons/httpclient/src/examples/FormLoginDemo.java?rev=1.1&content-type=text/vnd.viewcvs-markup

and here's the link to all their code samples:

http://cvs.apache.org/viewcvs/jakarta-commons/httpclient/src/examples/

The key for me was seeing that you had to manage redirects sort of manually as seen in the example I pointed out. 

There was one other thing that I'm not very sure about (it's been a few weeks since I've worked with this). but, out of the things I tried to get stuff working, it sticks in my mind as having helped. It was to set the headers to "emulate" one of the well known browsers. I seem to recall that the site I was trying to hit wasn't working right so I examined what I was sending vs. what the browser sent, then I set everything (header stuff) to the match what it was sending and I was able to get further along (still having some other problems but definately made progress once I did that).

Here's a snippet of what I did:


PostMethod method = new PostMethod( aUrl );

method.setUseExpectHeader( false );

method.setFollowRedirects(true);


method.setStrictMode(false);

method.setRequestHeader(new Header("user-agent","Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)" ) );

method.setRequestHeader( new Header( "accept", "*/*" ) );

method.setRequestHeader( new Header( "accept-language", "en-us" ) );

method.setRequestHeader( new Header( "accept-encoding", "gzip, deflate" ) );

method.setRequestHeader( new Header( "connection", "Keep-Alive" ) );

method.setRequestHeader( new Header( "cache-control", "no-cache" ) );



Hope this helps. If it does, let me know and maybe I'll post something to the mailing list.

Ed


Nate wrote:

----- Original Message ----- 
From: "Nate" 
To: 
Sent: Thursday, June 26, 2003 8:10 AM


> I have a question for anybody using the HttpClient component. Is there
> anything in particular that has to be done to enable cookies? I have
> already set the policy (tried all 3) in the HttpState that is used by the
> client, but the site I am attempting to communicate with still thinks
> cookies are turned off.
> 

---------------------------------------------------------------------
To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org


---------------------------------
Do you Yahoo!?
SBC Yahoo! DSL - Now only $29.95 per month!

---------------------------------
Do you Yahoo!?
SBC Yahoo! DSL - Now only $29.95 per month!

Re: HTTPClient

Posted by Ed Ludke <ed...@yahoo.com>.
Nate,
 
Hey, I'm no expert so I'm not replying to the forum with this but I have played a little with the HttpClient component with mixed sucess.  I hate to ask the obvious, but have you checked out the code samples?  There is one they published within the last few months that was particularly helpful.  Here's the link in case you haven't already seen it:
 
http://cvs.apache.org/viewcvs/jakarta-commons/httpclient/src/examples/FormLoginDemo.java?rev=1.1&content-type=text/vnd.viewcvs-markup
 
and here's the link to all their code samples:
 
http://cvs.apache.org/viewcvs/jakarta-commons/httpclient/src/examples/
 
The key for me was seeing that you had to manage redirects sort of manually as seen in the example I pointed out.  
 
There was one other thing that I'm not very sure about (it's been a few weeks since I've worked with this).  but, out of the things I tried to get stuff working, it sticks in my mind as having helped.  It was to set the headers to "emulate" one of the well known browsers.  I seem to recall that the site I was trying to hit wasn't working right so I examined what I was sending vs. what the browser sent, then I set everything (header stuff) to the match what it was sending and I was able to get further along (still having some other problems but definately made progress once I did that).
 
Here's a snippet of what I did:
 

PostMethod method = new PostMethod( aUrl );

method.setUseExpectHeader( false );

method.setFollowRedirects(true);


method.setStrictMode(false);

method.setRequestHeader(new Header("user-agent","Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)" ) );

method.setRequestHeader( new Header( "accept", "*/*" ) );

method.setRequestHeader( new Header( "accept-language", "en-us" ) );

method.setRequestHeader( new Header( "accept-encoding", "gzip, deflate" ) );

method.setRequestHeader( new Header( "connection", "Keep-Alive" ) );

method.setRequestHeader( new Header( "cache-control", "no-cache" ) );

 

Hope this helps.  If it does, let me know and maybe I'll post something to the mailing list.

Ed


Nate <nm...@charter.net> wrote:

----- Original Message ----- 
From: "Nate" 
To: 
Sent: Thursday, June 26, 2003 8:10 AM


> I have a question for anybody using the HttpClient component. Is there
> anything in particular that has to be done to enable cookies? I have
> already set the policy (tried all 3) in the HttpState that is used by the
> client, but the site I am attempting to communicate with still thinks
> cookies are turned off.
> 

---------------------------------------------------------------------
To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org


---------------------------------
Do you Yahoo!?
SBC Yahoo! DSL - Now only $29.95 per month!