POSTing binary data and nsIStringInputStream
[email protected] Thu, 1 May 2008 17:07:18 -0700 (PDT)
| Newsgroups | gmane.comp.mozilla.devel.java |
|---|---|
| Organization | http://groups.google.com |
| Message-ID | <f206d1db-3f96-4264-8fda-f65b8d4c8761__44767.4428266056$1209687093$gmane$org@z72g2000hsb.googlegroups.com> |
Hi all,
I have embedded browser into my applicaction using JavaXPCOM.
Now I need to send binary data via POST http requests (uploading files
onto a server) .
I found how to do this using nsIStringInputStream, it works great when
data is text,
but unfortunately it's method
setData()
gets as a parameter java String, not byte array, so it isn't usable
for binary data.
Does anybody know any sollution? Maybe there is posibility to build
nsI(Binary)InputStream from nsIBinaryOutputStream?
here is the code I use to load page with POST attached:
org.mozilla.interfaces.nsIWebNavigation wn =
(org.mozilla.interfaces.nsIWebNavigation)
webBrowser.queryInterface(nsIWebNavigation.NS_IWEBNAVIGATION_IID_STR);
nsIComponentManager cm = Mozilla.getInstance().getComponentManager();
nsIStringInputStream stringStream = (nsIStringInputStream)
cm.createInstanceByContractID("@mozilla.org/io/string-input-stream;1"
, (nsISupports) null,
nsIStringInputStream.NS_ISTRINGINPUTSTREAM_IID);
stringStream.setData(new String (POST), POST.length);
nsIMIMEInputStream postData = (nsIMIMEInputStream)
cm.createInstanceByContractID("@mozilla.org/network/mime-input-stream;
1"
, (nsISupports) null, nsIMIMEInputStream.NS_IMIMEINPUTSTREAM_IID);
postData.addHeader("Content-Type", contentType);
postData.setAddContentLength(true);
postData.setData(stringStream);
wn.loadURI(URL, nsIWebNavigation.LOAD_FLAGS_NONE, (nsIURI) null,
postData, null);
regards
bart