简体   繁体   English

以功能方式将主体添加到带有节点的HTTP发布请求中

[英]Add body to a HTTP post request with node in a functional way

I have the following code in a test: 我在测试中有以下代码:

var req = request(App)
  .post(postUrl)
  .set('Authorization', authorizationToken);

req.expect(201)
  .end(done);

And I want to add a body to the request. 我想在请求中添加一个body

I can't find any possible way to do it maintaining this style, the only way I found is by creating an object with all the proper data inside and then pass it to the request. 我找不到保持这种样式的任何可能方法,我发现的唯一方法是通过创建一个内部包含所有适当数据的对象,然后将其传递给请求。 Is it possible to add it? 可以添加吗?

I think you use supertest library, then if you want send post data you should do like this: 我认为您使用的是超级测试库,那么如果要发送帖子数据,您应该这样做:

var postData = {
   "field":1,
   "field1": "test"
};

var req = request(App)
  .post(postUrl)
  .set('Authorization', authorizationToken)
  .send(postData);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM