chai-http icon indicating copy to clipboard operation
chai-http copied to clipboard

HTTP POST with form fields not working

Open Doogiemuc opened this issue 9 years ago • 6 comments

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) { ... }

Doogiemuc avatar Apr 29 '16 12:04 Doogiemuc

I can confirm. I tried everything, but could not make .field() work. I could post data only with .send().

ghost avatar May 16 '16 08:05 ghost

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.

keithamus avatar May 16 '16 09:05 keithamus

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.

dman777 avatar May 08 '17 03:05 dman777

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 avatar Jun 20 '17 22:06 wzup

@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.

meeber avatar Jun 20 '17 23:06 meeber

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?

coinop-logan avatar May 02 '23 03:05 coinop-logan