chai-http
chai-http copied to clipboard
HTTP POST with form fields not working
see http://stackoverflow.com/a/36938187/6113110
It seems that simply the chai-http documentation is wrong. It sais:
// Send some Form Data
chai.request(app)
.post('/user/me')
.field('_method', 'put')
.field('password', '123')
.field('confirmPassword', '123')
Which does NOT work. This worked for me:
chai.request(app)
.post('/create')
.send({
title: 'Dummy title',
description: 'Dummy description'
})
.end(function(err, res) { ... }
I can confirm. I tried everything, but could not make .field() work. I could post data only with .send().
Hey @Doogiemuc thanks for the issue. Thanks @C00bra for confirming
Do either of you have the time to work on a PR fixing the documentation? Contributors get a permanent place in our hall of fame.
I hit this issue also. I don't believe the documentation/README is updated with use send({ obj: property}) instead of .field() for POST.
@keithamus should there even be a .field() method for PUT on forms? I don't believe HTML forms support PUT.
Same issue here https://github.com/chaijs/chai-http/issues/165 Thanks a lot for not documenting it. I wasted 1 hour to understand that plugin's README is just a fantasy that has nothing to do with reality
.send() by the way doesn't work either
@wzup As mentioned in the other thread, please check out https://github.com/chaijs/chai-http/pull/97#issuecomment-222397088; I think it may relate to the issue you're running into.
I get that you're frustrated but please understand that this is a 100% community-driven project that relies on people like yourself discovering issues or things that frustrate them and then submitting a PR to fix them so that future people don't run into the same issue. The original creator of this plugin hasn't been around since like 2013. I've never used this plugin myself but check in from time-to-time to help troubleshoot an issue or review a PR.
This actually does seem to be supported now. I came across this thread googling some other issue - I'm able to use the .field() method just fine. Maybe this issue can be closed?