• 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)
        }
    })

  • 相关阅读:
    【尺取法】
    [USACO12MAR]花盆Flowerpot [单调队列]
    数据库笔记
    NYOJ 91 阶乘之和(贪心)
    NYOJ 71 独木舟上的旅行(贪心)
    水池数目(DFS)
    poj 1164城堡问题(DFS)
    NYOJ 12 喷水装置(二)( 贪心)
    NYOJ 6(贪心)
    NYOJ 45( 分治,大数)
  • 原文地址:https://www.cnblogs.com/liessay/p/14047276.html
Copyright © 2020-2023  润新知