【问题标题】:Changing default header of Request in Babel在 Babel 中更改请求的默认标头
【发布时间】:2017-08-16 02:46:38
【问题描述】:

我是 Babel 的新手,并尝试使用标头“Content-Type”作为“application/json”发出 POST 请求。是否有任何更改 Request 标头的文档?

  import Request from 'request-promise-native'
  const result = await Request
      .post(`some url`)
      .auth(authId, secretToken,false)
      .form({
        text: "hello"
      })
  console.log(result);
  return JSON.parse(result)

【问题讨论】:

  • Request 与 Babel 转译器有什么关系?!

标签: javascript node.js http-headers request-promise


【解决方案1】:

只需像这样添加一个标题对象:

.headers({
    'Content-Type': 'application/json'
})

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-05-02
    • 2017-03-06
    • 1970-01-01
    • 2018-07-16
    • 2021-02-05
    • 1970-01-01
    • 2021-10-09
    • 1970-01-01
    相关资源
    最近更新 更多