简体   繁体   中英

API Post request authorization 401 in jquery

I think I have searched through the entire web for an answer and I'm still stuck. I try to console log a response from cinesa.es POST api but I can't get through the authorization problem.

I tried in postman and get an answer with the key I got from them placed in the body, but on the web I only get a 401 response with false.

The error code before response in console: POST https://www.cinesa.es/ApiFilms net::ERR_ABORTED 401

$(document).ready(function () {

var request = new Request('https://www.cinesa.es/ApiFilms', {
    method: 'POST', 
    mode: 'cors', 
    redirect: 'follow',
    headers: new Headers({
        'WWW-Authenticate': 'Basic',
        'Content-Type': 'multipart/json',
        'Authorization': 'XXXXXXX'
    })
});

// Now use it!
fetch(request).then(function(response) { 
    console.log(response); /* handle response */ 
});

Any adwise how to move forward from this?

Big thanks in advance!

According to http header authorization official doc you must specify authorization[space]secret key. Have u tried to do so?

So in your particaular case it has to be:

{Authorization: Basic XXXXXX}

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