【问题标题】:Trying to implement axios with post in body with headers inside尝试在正文中使用带有标题的帖子来实现 axios
【发布时间】:2020-02-13 00:14:08
【问题描述】:

我正在 vueNative App 中使用 wordpress 实现 jwt。当我调用 api 时,我得到临时标题显示警告。我也收到 403 错误。下面是我编写的代码。

 axios.post('https://ishopee.in/wp-json/jwt-auth/v1/token',null,{
                    headers: {
                    'username': 'nayanjariwala123456789@gmail.com',
                    'password': 'Baby_0123'
                    }
                })
                .then(res => {
                    console.log("---->SuccessFully Login".res);
                })
                .catch(err => {
                    console.log('--->'+err); 
                })

这是我从我的 vue 原生应用发出的请求

header
Request URL: https://ishopee.in/wp-json/jwt-auth/v1/token
Request Method: POST
Status Code: 403 Forbidden
Referrer Policy: no-referrer-when-downgrade

Response Headers
Access-Control-Allow-Headers: Authorization, Content-Type
Access-Control-Expose-Headers: X-WP-Total, X-WP-TotalPages
Allow: POST
Alt-Svc: quic=":443"; ma=2592000; v="39,43,46", h3-22=":443"; ma=2592000
Cache-Control: no-store, no-cache, must-revalidate
Connection: Keep-Alive
Content-Type: application/json; charset=UTF-8
Date: Wed, 16 Oct 2019 08:33:00 GMT
Expires: Thu, 19 Nov 1981 08:52:00 GMT
Link: <https://ishopee.in/wp-json/>; rel="https://api.w.org/"
null: HTTP/1.1 403 Forbidden
Pragma: no-cache
Server: LiteSpeed
Set-Cookie: PHPSESSID=dd9ecfdbdae48539a6bd1d1847d68c1d; path=/
Transfer-Encoding: chunked
X-Android-Received-Millis: 1571214780555
X-Android-Response-Source: NETWORK 403
X-Android-Selected-Protocol: http/1.1
X-Android-Sent-Millis: 1571214777449
X-Content-Type-Options: nosniff
X-Powered-By: PHP/7.1.28
X-Robots-Tag: noindex

Request Header
Provisional headers are shown
Accept: application/json, text/plain, */*
Content-Type: application/x-www-form-urlencoded
password: Baby_0123
username: nayanjariwala123456789@gmail.com

【问题讨论】:

  • 您是否使用 REST 客户端验证了凭据的 API 响应?
  • 是的,它在邮递员中工作
  • 你确定你必须传递标题信息吗?你在邮递员那里做同样的事情吗?看起来您的 API 似乎接受 JSON 正文而不是标头上的用户名和密码。

标签: wordpress jwt axios nativescript vue-native


【解决方案1】:

JSON 正文似乎工作我提出了以下请求,现在它工作了

axios.post('https://ishopee.in/wp-json/jwt-auth/v1/token',
                    {
                        'username': 'nayanjariwala123456789@gmail.com',
                        'password': 'Baby_123'
                    }
                })
                .then(res => {
                    console.log("--->SuccessFully Login".res);
                })
                .catch(err => {
                    console.log('--->'+err); 
                })

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-07-21
    • 2018-08-30
    • 2021-09-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多