简体   繁体   中英

How to pass authorization in Javascript HTTP request?

What is the error in my Javascript code?

function getAllLeads() {
    client.request.get("https://padmanabh.freshsales.io/api/leads/filters", {
        headers: {
            Authorization: "O5n0xfwgtg",
            "Content-Type": "application/json;charset=utf-8"
        }
    })
    .then(function () {
        console.error("Success");
        })
    .catch(function (error) {
        console.error(error);
    });
}

A similar request in curl is working as follows,

curl -H "Authorization: Token token=O5n0xfwgtg" -H "Content-Type: application/json" -X GET "https://padmanabh.freshsales.io/api/leads/filters

(API_KEY is modified so please don't try it)

As written in your question :

function getAllLeads() {
    client.request.get("https://padmanabh.freshsales.io/api/leads/filters", {
        headers: {
            Authorization:  = "O5n0xfwgtg",
            "Content-Type": "application/json;charset=utf-8"
        }
    })

Authorization: = "O5n0xfwgtg", is missing Token token =

You can possibly find an answer here : Basic Authentication Using JavaScript

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM