You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@mina.apache.org by tedc <te...@ms01.dahan.edu.tw> on 2007/09/04 04:37:34 UTC

Can someone provide http client example

Dear all :
I had seen someone have http client program of mina, but have some can give
a example like http server. I will try to see jgenender program, and don't
know how to use it.
anyone can give me some advice ........
Thanks 
Ted Chen
-- 
View this message in context: http://www.nabble.com/Can-someone-provide-http-client-example-tf4375080s16868.html#a12470749
Sent from the Apache MINA Support Forum mailing list archive at Nabble.com.


Re: Can someone provide http client example

Posted by Mark <el...@gmail.com>.
I just checked in the wget class.  Find it in
org.apache.mina.example.httpclient.Wget



On 9/5/07, Mark <el...@gmail.com> wrote:
>
> you will need to a little bit of reverse engineering to see how
> google/yahoo places the search criteria into the url.
>
> BTW, I am working on some examples that I will be placing into the
> examples sub-project.  Gimme another day or 2 and will have some stuff.  I
> would like to get a wget-like program as well as some search tools
> working...
>
>
>
> On 9/5/07, tedc <te...@ms01.dahan.edu.tw> wrote:
> >
> >
> > Hi Jeff:
> > Thanks for your help. Now I can send the http request to server, but I
> > recevie the request error from yahoo. And how can I send the query
> > string to
> > Google.
> > Thanks for your help.
> > Ted
> >
> >
> > jgenender wrote:
> > >
> > > Hi Ted,
> > >
> > > A good example of how to use it is in AsyncHttpClientTest.java.
> > >
> > > The code still needs a bit of work and will undergo a few changes as
> > it
> > > still has some functionality needed, but here is the gist of how to
> > use
> > > it.
> > >
> > > You need to create an implementation of the AsyncHttpClientCallback.
> > >
> > > This is where you get notified of your response.  In particular, you
> > > will be most interested in the onResponse() call.
> > >
> > > You then create a connection, let say you are going to yahoo...
> > >
> > > MyCallBack callback = new MyCallBack(); // This is your Callback impl
> > > AsyncHttpClient ahc =
> > >            new AsyncHttpClient( " http://www.yahoo.com", callback );
> > > ahc.connect();
> > >
> > > Once you have made the connection, you need to set up your request for
> > > the URI.  You can set request parameters, cookies, declare the method
> > > type, etc (look at the HttpRequestMessage.java for all the cool stuff
> > > you can do with it).  But keeping it simple..:
> > >
> > > HttpRequestMessage request = new HttpRequestMessage("/index.html");
> > >
> > > Then you send the request:
> > >
> > > ahc.sendRequest( request );
> > >
> > > When you receive a response, your callback should contain a
> > > HttpResponseMessage in the OnResponse().
> > >
> > > Let me know if that helped.
> > >
> > > Jeff
> > >
> > > tedc wrote:
> > >> Dear all :
> > >> I had seen someone have http client program of mina, but have some
> > can
> > >> give
> > >> a example like http server. I will try to see jgenender program, and
> > >> don't
> > >> know how to use it.
> > >> anyone can give me some advice ........
> > >> Thanks
> > >> Ted Chen
> > >
> > >
> >
> > --
> > View this message in context:
> > http://www.nabble.com/Can-someone-provide-http-client-example-tf4375080s16868.html#a12494325
> > Sent from the Apache MINA Support Forum mailing list archive at
> > Nabble.com.
> >
> >
>
>
> --
> ..Cheers
> Mark




-- 
..Cheers
Mark

Re: Can someone provide http client example

Posted by Mark <el...@gmail.com>.
you will need to a little bit of reverse engineering to see how google/yahoo
places the search criteria into the url.

BTW, I am working on some examples that I will be placing into the examples
sub-project.  Gimme another day or 2 and will have some stuff.  I would like
to get a wget-like program as well as some search tools working...



On 9/5/07, tedc <te...@ms01.dahan.edu.tw> wrote:
>
>
> Hi Jeff:
> Thanks for your help. Now I can send the http request to server, but I
> recevie the request error from yahoo. And how can I send the query string
> to
> Google.
> Thanks for your help.
> Ted
>
>
> jgenender wrote:
> >
> > Hi Ted,
> >
> > A good example of how to use it is in AsyncHttpClientTest.java.
> >
> > The code still needs a bit of work and will undergo a few changes as it
> > still has some functionality needed, but here is the gist of how to use
> > it.
> >
> > You need to create an implementation of the AsyncHttpClientCallback.
> >
> > This is where you get notified of your response.  In particular, you
> > will be most interested in the onResponse() call.
> >
> > You then create a connection, let say you are going to yahoo...
> >
> > MyCallBack callback = new MyCallBack(); // This is your Callback impl
> > AsyncHttpClient ahc =
> >            new AsyncHttpClient( "http://www.yahoo.com", callback );
> > ahc.connect();
> >
> > Once you have made the connection, you need to set up your request for
> > the URI.  You can set request parameters, cookies, declare the method
> > type, etc (look at the HttpRequestMessage.java for all the cool stuff
> > you can do with it).  But keeping it simple..:
> >
> > HttpRequestMessage request = new HttpRequestMessage("/index.html");
> >
> > Then you send the request:
> >
> > ahc.sendRequest( request );
> >
> > When you receive a response, your callback should contain a
> > HttpResponseMessage in the OnResponse().
> >
> > Let me know if that helped.
> >
> > Jeff
> >
> > tedc wrote:
> >> Dear all :
> >> I had seen someone have http client program of mina, but have some can
> >> give
> >> a example like http server. I will try to see jgenender program, and
> >> don't
> >> know how to use it.
> >> anyone can give me some advice ........
> >> Thanks
> >> Ted Chen
> >
> >
>
> --
> View this message in context:
> http://www.nabble.com/Can-someone-provide-http-client-example-tf4375080s16868.html#a12494325
> Sent from the Apache MINA Support Forum mailing list archive at Nabble.com
> .
>
>


-- 
..Cheers
Mark

Re: Can someone provide http client example

Posted by Jeff Genender <jg...@apache.org>.
Hi Ted,

Yep...the error is a bug on how he handle the Host header.  I opened a
JIRA and attached a patch to fix it.

https://issues.apache.org/jira/browse/DIRMINA-433

Thanks,

Jeff

tedc wrote:
> Hi Jeff:
> Thanks for your help. Now I can send the http request to server, but I
> recevie the request error from yahoo. And how can I send the query string to
> Google.
> Thanks for your help.
> Ted 
> 
> 
> jgenender wrote:
>> Hi Ted,
>>
>> A good example of how to use it is in AsyncHttpClientTest.java.
>>
>> The code still needs a bit of work and will undergo a few changes as it
>> still has some functionality needed, but here is the gist of how to use
>> it.
>>
>> You need to create an implementation of the AsyncHttpClientCallback.
>>
>> This is where you get notified of your response.  In particular, you
>> will be most interested in the onResponse() call.
>>
>> You then create a connection, let say you are going to yahoo...
>>
>> MyCallBack callback = new MyCallBack(); // This is your Callback impl
>> AsyncHttpClient ahc =
>>            new AsyncHttpClient( "http://www.yahoo.com", callback );
>> ahc.connect();
>>
>> Once you have made the connection, you need to set up your request for
>> the URI.  You can set request parameters, cookies, declare the method
>> type, etc (look at the HttpRequestMessage.java for all the cool stuff
>> you can do with it).  But keeping it simple..:
>>
>> HttpRequestMessage request = new HttpRequestMessage("/index.html");
>>
>> Then you send the request:
>>
>> ahc.sendRequest( request );
>>
>> When you receive a response, your callback should contain a
>> HttpResponseMessage in the OnResponse().
>>
>> Let me know if that helped.
>>
>> Jeff
>>
>> tedc wrote:
>>> Dear all :
>>> I had seen someone have http client program of mina, but have some can
>>> give
>>> a example like http server. I will try to see jgenender program, and
>>> don't
>>> know how to use it.
>>> anyone can give me some advice ........
>>> Thanks 
>>> Ted Chen
>>
> 

Re: Can someone provide http client example

Posted by tedc <te...@ms01.dahan.edu.tw>.
Hi Jeff:
Thanks for your help. Now I can send the http request to server, but I
recevie the request error from yahoo. And how can I send the query string to
Google.
Thanks for your help.
Ted 


jgenender wrote:
> 
> Hi Ted,
> 
> A good example of how to use it is in AsyncHttpClientTest.java.
> 
> The code still needs a bit of work and will undergo a few changes as it
> still has some functionality needed, but here is the gist of how to use
> it.
> 
> You need to create an implementation of the AsyncHttpClientCallback.
> 
> This is where you get notified of your response.  In particular, you
> will be most interested in the onResponse() call.
> 
> You then create a connection, let say you are going to yahoo...
> 
> MyCallBack callback = new MyCallBack(); // This is your Callback impl
> AsyncHttpClient ahc =
>            new AsyncHttpClient( "http://www.yahoo.com", callback );
> ahc.connect();
> 
> Once you have made the connection, you need to set up your request for
> the URI.  You can set request parameters, cookies, declare the method
> type, etc (look at the HttpRequestMessage.java for all the cool stuff
> you can do with it).  But keeping it simple..:
> 
> HttpRequestMessage request = new HttpRequestMessage("/index.html");
> 
> Then you send the request:
> 
> ahc.sendRequest( request );
> 
> When you receive a response, your callback should contain a
> HttpResponseMessage in the OnResponse().
> 
> Let me know if that helped.
> 
> Jeff
> 
> tedc wrote:
>> Dear all :
>> I had seen someone have http client program of mina, but have some can
>> give
>> a example like http server. I will try to see jgenender program, and
>> don't
>> know how to use it.
>> anyone can give me some advice ........
>> Thanks 
>> Ted Chen
> 
> 

-- 
View this message in context: http://www.nabble.com/Can-someone-provide-http-client-example-tf4375080s16868.html#a12494325
Sent from the Apache MINA Support Forum mailing list archive at Nabble.com.


Re: Can someone provide http client example

Posted by Jeff Genender <jg...@apache.org>.
Hi Ted,

A good example of how to use it is in AsyncHttpClientTest.java.

The code still needs a bit of work and will undergo a few changes as it
still has some functionality needed, but here is the gist of how to use it.

You need to create an implementation of the AsyncHttpClientCallback.

This is where you get notified of your response.  In particular, you
will be most interested in the onResponse() call.

You then create a connection, let say you are going to yahoo...

MyCallBack callback = new MyCallBack(); // This is your Callback impl
AsyncHttpClient ahc =
           new AsyncHttpClient( "http://www.yahoo.com", callback );
ahc.connect();

Once you have made the connection, you need to set up your request for
the URI.  You can set request parameters, cookies, declare the method
type, etc (look at the HttpRequestMessage.java for all the cool stuff
you can do with it).  But keeping it simple..:

HttpRequestMessage request = new HttpRequestMessage("/index.html");

Then you send the request:

ahc.sendRequest( request );

When you receive a response, your callback should contain a
HttpResponseMessage in the OnResponse().

Let me know if that helped.

Jeff

tedc wrote:
> Dear all :
> I had seen someone have http client program of mina, but have some can give
> a example like http server. I will try to see jgenender program, and don't
> know how to use it.
> anyone can give me some advice ........
> Thanks 
> Ted Chen