简体   繁体   English

Django rest 框架如何在nextjs post请求中传递授权令牌?

[英]Django rest framework how to pass authorizing token in nextjs post request?

How to pass django authorization token in nextjs axois.如何在 nextjs axois 中传递 django 授权令牌。 I tried this for pass authorization token but getting 404 error.我试过这个用于传递授权令牌,但出现 404 错误。

let token = "Token 8736be9dba6ccb11208a536f3531bccc686cf88d"
await axios.post(url,{
          headers: { Authorization: `Bearer ${token}` },
          contact_name:contact_name,contact_email:contact_email,contact_body:contact_body,
          
        }) 

I believe you're sending the bearer token the correct way.我相信您正在以正确的方式发送不记名令牌。 Try removing "Token" from the token variable and it should work尝试从令牌变量中删除“令牌”,它应该可以工作

Correct code:正确代码:

let token = "8736be9dba6ccb11208a536f3531bccc686cf88d"
await axios.post(url,{
          headers: { Authorization: `Bearer ${token}` },
          contact_name:contact_name,contact_email:contact_email,contact_body:contact_body,
          
        }) 

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

相关问题 Axios 发布请求不适用于 Django Rest 框架 - Axios post request not working with Django Rest Framework 请求当前用户API令牌Django REST Framework - Request current users API token Django REST Framework 从 js 向 django rest 框架发出 post 请求 - Make post request from js to django rest framework 请求中不支持的媒体类型“text/plain;charset=UTF-8”。 NextJS API 错误与 Django Rest 框架 - Unsupported media type "text/plain;charset=UTF-8" in request. NextJS API error with Django Rest Framework Django Rest Framework - 错误的请求 - Django Rest Framework - Bad request Django Rest 框架说 CSRF 验证失败,尽管 CSRF 令牌包含在 axios POST Z0995EFZ640F39E - Django Rest Framework says CSRF verification failed despite CSRF token is included in axios POST header 如何将Django的CSRF令牌添加到jQuery POST请求的标头中? - How to add Django's CSRF token to the header of a jQuery POST request? 如何在 Ionic React 应用程序中使用 Axios 将第一个请求响应的令牌传递给第二个请求 header(2 个发布请求) - How to pass Token of the first request response to the second request header, using Axios in an Ionic React app (2 Post Requests) nextjs中如何使用POST api token使用第三方API - How to use POST api token to use third party APIs in nextjs 使用Javascript访问Django Rest Framework API-获取令牌 - Access Django Rest Framework API using Javascript - getting a Token
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM