You are viewing a plain text version of this content. The canonical link for it is here.
Posted to httpclient-users@hc.apache.org by Linuxhippy <li...@web.de> on 2005/04/30 21:32:08 UTC

Easy way to use self-defined "Http"-Methods...

Hello!

First of all let me say that HttpClient is great compared to 
HttpURLConnection ;-). Its even great not compared to this ugly class *g*

I am currently writing some code that should connect to a WebDAV server, 
whereas WebDAV is just a bit extended Http protocol.
I've already posted on the Slide lists but I think this was defentivly 
the wrong place since Slide was made to cover WebDav via API and not to 
send arround raw HTTP-Requests ;-)

I saw that there are predefined methods like Get/Post and so on in the 
methods-package, what I need to do is what can be done in C# by the 
following lines of code:
   HttpWebRequest HttpWRequest = (HttpWebRequest)WebRequest.Create(myUri);
        HttpWRequest.KeepAlive = false;
        HttpWRequest.Headers.Set("Pragma", "no-cache");
        HttpWRequest.ContentType =  "text/xml";
        HttpWRequest.ContentLength = sQuery.Length;
        HttpWRequest.Method = "MKCOL";                       //Howto 
specify an own Request-Method using HttpClient
         Stream QueryStream = HttpWRequest.GetRequestStream();
        // Write the data to be posted to the Request Stream
        QueryStream.Write(ByteQuery,0,ByteQuery.Length);

Please don't think I am a MS fan, I even don't speak C#, but this was 
the only sample I found.
Basically I think this is either a PUT or POST (does anybody know what 
HttpWRequest really does?), but I don't know howto archive the same via 
HttpClient, since I do not want to create a whole new method-class which 
implements HttpMethod.
Would it be enough to just overwrite the HttpPost-class  and return 
"MKCOL" as string?

Would be really great if somebody could help me...

Thanks in advance, lg Clemens




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


Thanks! - Re: Easy way to use self-defined "Http"-Methods...

Posted by Linuxhippy <li...@web.de>.
Hi Oleg,

>Clemens,
>
>It should be perfectly okay to subclass the PostMethod class and
>override the getName() method. Otherwise I see no difference between the
>plain HTTP POST and WebDav MKCOL methods at least based on the sample
>code you have posted
>
>Cheers,
>
>Oleg
>
Just did not know its sooo easy ;-)
Thanks a lot, works great!

lg Clemens

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


Re: Easy way to use self-defined "Http"-Methods...

Posted by Oleg Kalnichevski <ol...@apache.org>.
Clemens,

It should be perfectly okay to subclass the PostMethod class and
override the getName() method. Otherwise I see no difference between the
plain HTTP POST and WebDav MKCOL methods at least based on the sample
code you have posted

Cheers,

Oleg

On Sat, 2005-04-30 at 19:32 +0000, Linuxhippy wrote:
> Hello!
> 
> First of all let me say that HttpClient is great compared to 
> HttpURLConnection ;-). Its even great not compared to this ugly class *g*
> 
> I am currently writing some code that should connect to a WebDAV server, 
> whereas WebDAV is just a bit extended Http protocol.
> I've already posted on the Slide lists but I think this was defentivly 
> the wrong place since Slide was made to cover WebDav via API and not to 
> send arround raw HTTP-Requests ;-)
> 
> I saw that there are predefined methods like Get/Post and so on in the 
> methods-package, what I need to do is what can be done in C# by the 
> following lines of code:
>    HttpWebRequest HttpWRequest = (HttpWebRequest)WebRequest.Create(myUri);
>         HttpWRequest.KeepAlive = false;
>         HttpWRequest.Headers.Set("Pragma", "no-cache");
>         HttpWRequest.ContentType =  "text/xml";
>         HttpWRequest.ContentLength = sQuery.Length;
>         HttpWRequest.Method = "MKCOL";                       //Howto 
> specify an own Request-Method using HttpClient
>          Stream QueryStream = HttpWRequest.GetRequestStream();
>         // Write the data to be posted to the Request Stream
>         QueryStream.Write(ByteQuery,0,ByteQuery.Length);
> 
> Please don't think I am a MS fan, I even don't speak C#, but this was 
> the only sample I found.
> Basically I think this is either a PUT or POST (does anybody know what 
> HttpWRequest really does?), but I don't know howto archive the same via 
> HttpClient, since I do not want to create a whole new method-class which 
> implements HttpMethod.
> Would it be enough to just overwrite the HttpPost-class  and return 
> "MKCOL" as string?
> 
> Would be really great if somebody could help me...
> 
> Thanks in advance, lg Clemens
> 
> 
> 
> 
> ---------------------------------------------------------------------
> 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