tacotuesday
tacotuesday

Reputation: 135

How to post data using node-http-ntlm?

I am trying to figure out how to actually post data using this node module: https://github.com/SamDecrock/node-http-ntlm

It looks like posting should be similar to: https://github.com/SamDecrock/node-httpreq#post

But the documentation for httpreq doesnt actually show POSTing a value, I only see parameters or how to POST an entire file. Im using node and have something along these lines:

NodeClient.prototype.create = function (xml) {

var options = {
    url: this.url,
    username: this.user,
    password: this.pw,
    domain: this.domain,
    headers: {
        'Content-type': 'text/plain'
    }
};

    return new Promise(function (resolve, reject) {
        httpntlm.post(options,
        function (err, resp) {
            if(err) {
                reject(err);
            }
            resolve(resp.body);
        });
   });
};

Obviously I never send my xml object, so I need to figure out how to include this. Reading the documentation hasnt lead me anywhere to this point.

Upvotes: 2

Views: 3898

Answers (2)

Sam
Sam

Reputation: 6132

You can POST xml like this:

var httpntlm = require('httpntlm');

var xml = '<?xml version="1.0" encoding="UTF-8"?>'; // replace this with your xml

httpntlm.post({
    url: "https://someurl.com",
    username: 'm$',
    password: 'stinks',
    workstation: 'choose.something',
    domain: '',
    body: xml,
    headers: { 'Content-Type': 'text/xml' }
}, function (err, res){
    if(err) return err;

    console.log(res.headers);
    console.log(res.body);
});

Upvotes: 5

tacotuesday
tacotuesday

Reputation: 135

To add content to the post, you can include the following options:

  1. json: if you want to send json directly (content-type is set to application/json)
  2. files: an object of files to upload (content-type is set to multipart/form-data; boundary=xxx)
  3. body: custom body content you want to send. If used, previous options will be ignored and your custom body will be sent. (content-type will not be set)

Upvotes: 2

Related Questions