Open bberry6 opened 9 years ago
Heres some example code...
var express = require('express'); var bodyParser = require('body-parser'); var bhttp = require('bhttp'); var app = express(); //app.use(bodyParser.json()); app.use(bodyParser.text()); app.post('/', function (req, res) { console.log("Server::headers: ",req.headers); console.log("Server::body: ",req.body); console.log("Server::params: ",req.params); res.sendStatus(200); }); var server = app.listen(3000, function(){ var opts = { url: "http://localhost:3000/", data: 'test' }; bhttp.post(opts.url, opts.data) .then(function(res){ console.log("Client::statusCode: ", res.statusCode); return bhttp.post(opts.url, opts.data, {headers: {"content-type":"text/plain"}}); }) .then(function(res){ console.log("Client::statusCode: ", res.statusCode); process.exit(); }); });
And the output...
Server::headers: { 'user-agent': 'bhttp/1.2.1', 'content-length': '4', host: 'localhost:3000', connection: 'close' } Server::body: {} Client::statusCode: 200 Server::headers: { 'content-type': 'text/plain', 'user-agent': 'bhttp/1.2.1', 'content-length': '4', host: 'localhost:3000', connection: 'close' } Server::body: test Client::statusCode: 200
There isn't any content-type passed in the first post. Only when manually defining the content type can the text/plain type be set.
Thanks!
To do:
text/plain
Heres some example code...
And the output...
There isn't any content-type passed in the first post. Only when manually defining the content type can the text/plain type be set.
Thanks!