【问题标题】:ReactJS token base post?ReactJS 令牌基础帖子?
【发布时间】:2020-02-01 16:00:27
【问题描述】:

我想将数据发送到以下 URL。我发送了从令牌验证收到的令牌,但它给出了“错误请求”错误。你能帮我吗?

handleSubmit() {
   fetch('http://127.0.0.1:8000/api/debt/create',{
       method: 'POST',
       headers: {
           Authorization: `Bearer ${localStorage.getItem('id_token')}`,
           'Content-Type': 'application/json'
       },
       body: JSON.stringify({
           user: '1',
           customer: '9',
           debtKey: 'b1d9ef1b-45ad-4dc5-80cc-95f7994c0aae',
           createduserKey: '0245abb9-2837-4f37-ae02-9be1b88887ef',
           totalDebt: 789,
           receivedAmount: 115,
           description: 'Debt description',
           paymentDate: '01.01.2019'
       }),
   }).then(response => {
       console.log(response);
       return response.json()
   }).then(json => {
       //this.setState({
       //    user:json
       //});
   });
 console.log("form gönderme ekranına düştü");
}

【问题讨论】:

  • 你能在api中发布代码吗?
  • 你可以尝试在没有 JSON.stringify 的情况下发送正文吗?
  • 可以通过邮递员提出要求吗?
  • @FatimMzm 看看这个stackoverflow.com/a/58217732/8138584

标签: reactjs rest api django-rest-framework


【解决方案1】:

Authorizationkey 。它应该用引号引起来。

headers: {
       'Authorization': `Bearer ${localStorage.getItem('id_token')}`,
       'Content-Type': 'application/json'
   },

【讨论】:

    猜你喜欢
    • 2017-07-06
    • 2018-04-27
    • 1970-01-01
    • 2016-04-03
    • 1970-01-01
    • 2011-04-16
    • 2019-05-26
    • 1970-01-01
    • 2016-03-19
    相关资源
    最近更新 更多