hc-httpclient-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Mike Y <kemal...@yahoo.com>
Subject Re: very simple problem... how to post data to an HttpConnection...
Date Tue, 26 Oct 2004 22:12:40 GMT
Oleg,
 
Thank you for this. However, can I set the timeout
using HttpClient?  

For the sake of science, *is* it actually impossible
to use the HttpConnection class to post without
doing some kind of raw write?  (In other words,
looking up the http 'post' specs?)
 
Happy to be the first person posting!  My
application is that I'm trying to tie a Web site in to
a back-end order processing system through a proxy
server. In order to have a robust real-time
application, I need some way to control the timeout in
case of a network outage or the proxy doesn't return
its output in a timely manner -- 60 seconds is a very
long time for a customer to wait (I think that's the
default, anyway).

I was attracted to this project as a possible
solution because:

a) The API looked simple enough.  ;-) and 
b) I could control timeout with an appropriate level
of abstraction.  

I've done similar projects before in different ways,
and guess I was up for trying to find something new.
 
Sincerely,
Mike
 
 
> --- Oleg Kalnichevski <olegk@apache.org> wrote:
> 
> > Mike,
> > In fact, we strongly discourage the direct use of
> > HttpConnection class.
> > The preferred way is to let the connection manager
> > take care of the HTTP
> > connection business. Unless you have a real reason
> > to use HttpConnection
> > class directly, I'd recommend that you use
> > HttpClient instead
> > 
> > Something like that:
> >
>
=====================================================================
> > HttpClient client = new HttpClient();
> > PostMethod httppost = new
> > PostMethod("http://www.whatever.com");
> > 
> > File file = new File(args[0]);
> > httppost.setRequestBody(new
> FileInputStream(file));
> >
>
httppost.setRequestContentLength((int)file.length());
> > 
> > try {
> >   client.executeMethod(httppost);
> >   if (httppost.getStatusCode() !=
> HttpStatus.SC_OK)
> > {
> >     System.out.println("Unexpected failure: " +
> > httppost.getStatusLine());
> >   }
> >  
> >
>
System.out.println(httppost.getResponseBodyAsString());
> > } finally {
> >   httppost.releaseConnection();
> > }
> >
>
=====================================================================
> > 
> > BTW, you are the first ever user to post to the
> > httplclient-user list
> > 
> > ;-)
> > 
> > Cheers,
> > 
> > Oleg
> > 
> > 
> > On Tue, 2004-10-26 at 22:52, Mike Y wrote:
> > > As you might guess from the subject, I'm new
> here
> > > 
> > > I'm attempting to use the 2.0.2 version of this
> > > project to create a connection, post data to it,
> > and
> > > read the results, or at least get a Stream of
> > output
> > > that I can pass someplace else.
> > > 
> > > I've been reading the Javadocs and tutorials for
> > the
> > > last hour at least, the tutorials seem to
> > reference an
> > > HttpMethod class which can't actually be found
> in
> > the
> > > Javadocs or distribution. 
> > > 
> > > So, I'm not sure what I'm supposed to do. I
> have:
> > > 
> > > 1. String postRequest = " ... ";
> > > 2. HttpConnection c = new HttpConnection
> > > ("http://somesite/somedynamicpage.asp", 80);
> > > 3. c.setConnectionTimeout(someTimeoutValue);
> > > 
> > > 4. --- Need to post my request to my connection
> --
> > > 
> > > return c.getResponseInputStream();
> > > 
> > > I would greatly appreciate any help here.  I
> hope
> > this
> > > is not a stupid question.  I saw and read the
> docs
> > on
> > > the PostMethod, but it's not clear to me how
> this
> > > class interacts with HttpConnection.  This is
> > likely
> > > the result of my own mental deficiencies.  
> > > 
> > > For what it is worth, the tutorial I was looking
> > at
> > > was here:
> > > 
> > >
> >
>
http://cvs.apache.org/viewcvs.cgi/jakarta-commons/httpclient/src/examples/Attic/CustomHttpConnection.java?only_with_tag=HTTPCLIENT_2_0_BRANCH&view=markup).
> > > 
> > > --Mike
> > > 
> > > 
> > > 
> > > 		
> > > __________________________________
> > > Do you Yahoo!?
> > > Yahoo! Mail Address AutoComplete - You start. We
> > finish.
> > > http://promotions.yahoo.com/new_mail
> > > 
> > >
> >
>
---------------------------------------------------------------------
> > > To unsubscribe, e-mail:
> > httpclient-user-unsubscribe@jakarta.apache.org
> > > For additional commands, e-mail:
> > httpclient-user-help@jakarta.apache.org
> > > 
> > 
> > 
> >
>
---------------------------------------------------------------------
> > To unsubscribe, e-mail:
> > httpclient-user-unsubscribe@jakarta.apache.org
> > For additional commands, e-mail:
> > httpclient-user-help@jakarta.apache.org
> > 
> > 
> 
> 
> __________________________________________________
> Do You Yahoo!?
> Tired of spam?  Yahoo! Mail has the best spam
> protection around 
> http://mail.yahoo.com 
> 



	
		
__________________________________
Do you Yahoo!?
Yahoo! Mail - You care about security. So do we.
http://promotions.yahoo.com/new_mail

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


Mime
View raw message