Giter Site home page Giter Site logo

Comments (6)

dougwilson avatar dougwilson commented on March 29, 2024 1

How about just router.use(bodyParser.text({ type: 'urlencoded' }))? It should provide you the URL-encoded body as a string in req.body, then.

from body-parser.

charyorde avatar charyorde commented on March 29, 2024

Thanks @dougwilson
Tired that but req.body still returns {'username':'myname','password':'mypass'}

from body-parser.

dougwilson avatar dougwilson commented on March 29, 2024

Ok. It would be easier if I had fully complete code to run. This is the code I have that works for me:

var bodyParser = require('body-parser');
var express = require('express');

var app = express();
app.post('/login', bodyParser.text({ type: 'urlencoded' }), function(req, res) {
  console.log(req.body);
  if (!req.body) return res.sendStatus(400);

  var options = httpconn.httpOptions({
    resource: 'uaa',
    resourcePath: '/uaa/login.do',
    method: 'POST',
    headers: {'Referer': httpconn.buildUri('uaa') + '/uaa/login'}
  });
  var httpRequest = application.httprequest(options, function(response) {
      if(response.statusCode == 302) {
        res.send(response.headers);
      } 
  });
  httpRequest.write(req.body);
  httpRequest.end();
});

from body-parser.

dougwilson avatar dougwilson commented on March 29, 2024

Basically, the body can only be parsed one time so your bodyParser.text({ type: 'urlencoded' }) needs to be exclusive so it doesn't conflict with your bodyParser(). Ideally the best practice on the readme is you only ever use bodyParser middleware on the routes themselves (like above) rather than globally. This helps prevents conflicts.

from body-parser.

charyorde avatar charyorde commented on March 29, 2024

Awesome. Works now. Thanks

from body-parser.

kagan94 avatar kagan94 commented on March 29, 2024

In my case, the content-type of incoming requests was 'text/plain', so on the backend side I needed to parse it from that format:

app.use(parser.json({type: 'text/plain'}))

from body-parser.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.