Marek Lewczuk wrote:

Hello,
I have a problem with nsIStringInputStream interface. I want to make multipart POST to my http server. The problem is that all non-ascii chars are cuted-out from string. Look below:


var inputStream = Components.classes["@mozilla.org/io/string-input-stream;1"].createInstance(Components.interfaces.nsIStringInputStream);

inputStream.setData(this.text, -1);

"this.text" is a value from textbox widget. XUL document encoding is set to UTF-8.

Thanks in advance.

ML


It sounds like you should be using nsIBinaryOutputStream instead. Try this code:

var storage = Components.classes["@mozilla.org/storagestream;1"]
.createInstance(Components.interfaces.nsIStorageStream);
var out = storage.getOutputStream(0);


var binout = Components.classes["@mozilla.org/binaryoutputstream;1"]
.createInstance(Components.interfaces.nsIBinaryOutputStream);
binout.setOutputStream(out);
binout.writeUtf8Z(this.text);


Then when you are constructing the POST request, you can use this stream:

var in = storage.newInputStream(0);

The main issues with this solution are:

(1) writeUtf8Z places a NULL byte in the stream (maybe this is undesirable)
(2) this code uses unfrozen interfaces
(3) this code will only work in builds post 2004/03/02 (which means Moz 1.7 and later).
the problem is that nsIStorageStream was only recently exposed to JavaScript.
see bug 235744.


-Darin
_______________________________________________
Mozilla-xpcom mailing list
[EMAIL PROTECTED]
http://mail.mozilla.org/listinfo/mozilla-xpcom

Reply via email to