This is what I came across too. The token you are passing is incorrect.
Just Hardcode the token and pass, you will get the correct response. But if token is not passed in single quote '', then it will surely fail. It must be in format 'Authorization': 'Bearer YzE5ZTdiMjVlYzM5NjA2MGJkZTM5NjVlOTQ5YMmQ5ZjMwYjA0YmEzZmZjN2I1MmI4MDJkNQ', where after Bearer one space must be present, also single
Just hardcode the token and go through, you will get the correct answer. But if the token is not transferred in a single quote, '' then it will certainly fail. It should be in the "Authorization" format: "Media YzE5ZTdiMjVlYzM5NjA2MGJkZTM5NjVlOTQ5YMmQ5ZjMwYjA0YmEzZmZjN2I1MMI4MDJkNQ", where one space should be, one space must be present, one space must be present, one space must be present, D there must be one space inside enclosed in quotation marks, there must be one space, [D1, D1], inside should be one [1], and [1] must be in quotation marks;
var token = "YzE5ZTdiMjVlYzM5NjA2MGJkZTM5NjVlOTQ5YMmQ5ZjMwYjA0YmEzZmZjN2I1MmI4MDJkNQ"; var headers = { Authorization: "Bearer " + token, Accept: "application/json, text/plain, */*", "Content-Type": "application/json" };
IMP: the above code will work, but if you send something like:
Authorization: Media + YzE5ZTdiMjVlYzM5NjA2MGJkZTM5NjVlOTQ5YMmQ5ZjMwYjA0YmEzZmZjN2I1MmI4MDJkNQ, a crash will occur
or ----- the code below will also fail, I hope you understand the main difference
var token = YzE5ZTdiMjVlYzM5NjA2MGJkZTM5NjA0YmEzZmZjN2I1MmI4MDJkNQ; var headers = { Authorization: "Bearer " + token, Accept: "application/json, text/plain, */*", "Content-Type": "application/json" };
Athar
source share