uni-app 登錄Abp VNexe並獲取Token


uni.request方式登錄abp關鍵代碼如下,因abp獲取token需要用formdata方式請求所以需要加上請求頭
const baseUrl = 'http://127.0.0.1:44323';
uni.request({
    url: baseUrl + '/connect/token',
    method: 'POST',
    header: {
        'content-type': "application/x-www-form-urlencoded"
    },
    data: {
        grant_type: 'password',
        scope: 'shop',
        username: 'admin',
        password: '1q2w3E*',
        client_id: 'shop_App',
        client_secret: '1q2w3e*'
    },
    success: res => {
        if (res.statusCode === 200) {
            uni.setStorageSync('access_token', res.data.token_type + ' ' + res.data.access_token)
        } else {
            uni.showToast({
                icon: 'none',
                title: '登錄失敗!'
            })
        }
    }
});

測試獲取數據,請求數據需要在請求頭帶上Token

const baseUrl = 'http://127.0.0.1';
uni.getStorage({
    key: 'access_token',
    success: res => {
        uni.request({
            url: baseUrl + '/api/identity/users',
            method: 'GET',
            header: {
                'Authorization': res.data
            },
            success: res => {
                console.log(res)
            },
        });
    },
    fail: res => {
        console.log(res)
    }
})

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM