dancefingerx

在使用ajax请求业务接口时需要使用请求头进行身份验证,方式如下:

$(function () {
    $.ajax({
        type: \'GET\',
        url: \'/xxxx-api/openapi/url/getBusinessUrl\',
        data: \'ip=10.10.190.1&bizCode=JDCWFCX\',
        dataType: \'json\',
        beforeSend:function(xhr){
          xhr.setRequestHeader("Authorization","Basic "+"cGluZ2FuOjEyMzQ1Na==");
        },
        success:function (data) {
            console.log(data)
            if (data.errcode == 0) {
                alert("成功");
            }else {
                alert("失败")
            }
        }

    })
})
$(function () {
    $.ajax({
        type: \'GET\',
        url: \'/xxxx-api/openapi/url/getBusinessUrl\',
        data: \'ip=10.10.190.1&bizCode=JDCWFCX\',
        dataType: \'json\',
        headers: {"Authorization","Basic "+"cGluZ2FuOjEyMzQ1Na=="}
        success:function (data) {
            console.log(data)
            if (data.errcode == 0) {
                alert("成功");
            }else {
                alert("失败")
            }
        }

    })
})

分类:

技术点:

相关文章:

  • 2021-07-05
  • 2022-12-23
  • 2022-12-23
  • 2021-11-28
  • 2021-10-16
  • 2021-11-28
  • 2021-11-28
猜你喜欢
  • 2021-07-17
  • 2021-04-17
  • 2021-11-28
  • 2021-11-28
  • 2021-11-28
  • 2022-12-23
  • 2021-12-05
相关资源
相似解决方案