Re: HTTP communication
Darin Fisher <[email protected]> Mon, 31 Mar 2003 12:26:40 -0800
| Newsgroups | gmane.comp.mozilla.devel.netlib,gmane.comp.mozilla.devel.xpcom |
|---|---|
| Organization | Netscape Communications |
| Message-ID | <[email protected]> |
Tom Lee wrote:
> Hello,
>
> I have been looking for an example on how to use the HTTP functionality
> properly. I am particularly interested in POST, GET, ect... The application
> that I am currently working on needs to post an extremely large amount of
> data - so I would be in a loop sending 2k buffers with each iteration. Anty
> helop would be greatly appreciated.
>
>
tom,
you will need to use nsIUploadChannel and nsIHttpChannel to setup a post
request. here's some sample code:
var chan = ...
var uploadChan = chan.QueryInterface(
Components.interfaces.nsIUploadChannel);
uploadChan.setUploadStream(content, contentType, contentLen);
var httpChan = chan.QueryInterface(
Components.interfaces.nsIHttpChannel);
httpChan.method = "POST";
now, when you call "asyncOpen" on the channel, it will issue a HTTP POST
request instead of a GET. it will send the data contained in "content".
content must support nsIInputStream. you can either provide your own
implementation of nsIInputStream or use one of the existing
implementations found in xpcom/io, but beware none of the existing
implementations are frozen.
darin