JQuery - Petición con jquery ajax 403 y postman 200

 
Vista:
sin imagen de perfil

Petición con jquery ajax 403 y postman 200

Publicado por smn (1 intervención) el 08/08/2021 19:01:31
Estoy teniendo un problema que no se a que se debe, pasa que con el siguiente código estoy haciendo una petición a la api de clash of clans https://developer.clashofclans.com/#/ que me esta devolviendo un código de estatus 403, pero si lo hago con postman me funciona bien me devuelve el json, tambien cabe decir que es primera vez que uso una api con token (en el insti no te enseñan a usar una api con token

curl:
curl -X GET --header 'Accept: application/json' --header "authorization: Bearer <API token>" 'https://api.clashofclans.com/v1/leagues'

Request URL
https://api.clashofclans.com/v1/leagues

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
$(document).ready(function() {
    const Url = 'https://api.clashofclans.com/v1/leagues'
    const token = 'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzUxMiIsImtpZCI6IjI4YTMxOGY3LTAwMDAtYTFlYi03ZmExLTJjNzQzM2M2Y2NhNSJ9.eyJpc3MiOiJzdXBlcmNlbGwiLCJhdWQiOiJzdXBlcmNlbGw6Z2FtZWFwaSIsImp0aSI6IjIyZWNiMTgxLTk0OWMtNGUwNy05ZGZjLTcxYzU5N2NjODRkNiIsImlhdCI6MTYyODM3OTM5MCwic3ViIjoiZGV2ZWxvcGVyL2U0YTUzYWRiLTU2YmEtMWNmOC1hYjI2LTM1M2NkYmM0NDY0MiIsInNjb3BlcyI6WyJjbGFzaCJdLCJsaW1pdHMiOlt7InRpZXIiOiJkZXZlbG9wZXIvc2lsdmVyIiwidHlwZSI6InRocm90dGxpbmcifSx7ImNpZHJzIjpbIjE5MC4xNjAuMjEuNDYiXSwidHlwZSI6ImNsaWVudCJ9XX0.9874gl13I3omk9vV9HIILk0zdLSRx2RAHT5R0lPAC2l2qMk1HxWcl65fHAb5hXpcXyhaHOSsBew7n7jiSTbMSw'
 
    $('#boton').click(function() {
        $.ajax({
            url: Url,
            type: 'get',
            dataType: 'jsonp',
            headers: {
                'Accept': 'application/json',
                'Authorization': `Bearer ${token}`
            },
 
 
            success: function(resultado) {
                console.log(resultado)
            },
            error: function(error) {
                console.log(error)
            }
        })
    })
})
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder