0

I am trying to send an xml string to a third party server. The string has to be ISO-8859-8 encoded. Here's what I try using request and iconv-lite:

var request_xml = 'my xml string...';
var header = "<?xml version='1.0' encoding='ISO-8859-8'?>";
request_xml = header.concat(request_xml);
var buf = iconv.encode(request_xml, 'iso-8859-8');


var req = {
  url: env.url,
  method: 'post',
  form: {
    user: env.user,
    password: env.password,
    int_in: buf,
  }
};


request(req, function(err, res, body) { 
   ...
}

This just doesn't work, not sure If it's possible to pass a Buffer as a form data on request. Does anybody know a way ?

Thanks

Michael
  • 22,196
  • 33
  • 132
  • 187
  • It's definitely not possible. You need to encode buffer as a string. The most sensible encoding for arbitrary buffer is `base64`. – vkurchatkin Dec 30 '13 at 08:28
  • @vkurchatkin how do you mean ? I need the xml to be encoded in `iso-8859-8` and sent with `ContentType=application/x-www-form-urlencoded` – Michael Dec 30 '13 at 10:22
  • Oh, I see now. Not sure it is possible to do that with `request` form option, but you can compose `application/x-www-form-urlencoded` body manually, it's not that hard. – vkurchatkin Dec 30 '13 at 10:30
  • @vkurchatkin you mind giving an example of what you mean ? – Michael Dec 30 '13 at 11:43

0 Answers0