Status Code: 401 Unauthorized
this is the header request
access-control-request-headers: authorization,x-requested-with
authorization: Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiJ9.eyJhdWQiOiIxIiwianRpIjoiMzEyNzc2ZmFiZGQyYjllYTBiMWM1ODRjNmI0Mzg2NzQ5YmVlY2YwM2ZlMGIwOGE4NDgxMmFkYmRlNDcyZDNiNTE3NjkxY2RmOGNiYjQzNTAiLCJpYXQiOjE3MTM3NjQxMzIuNjEwMjM3LCJuYmYiOjE3MTM3NjQxMzIuNjEwMjQzLCJleHAiOjE3NDUzMDAxMzIuNTk2Njc2LCJzdWIiOiIxNSIsInNjb3BlcyI6W119.ejjZExqN7EhoXAp0p_wUeBVq6gzQlOGBNzAhmbXyKzCzVdL5pw5BcySlns1K2rLn5KoyVU8kw_-VJfT3RWe_UB83uakzz47-w1fd2a89NpwIY1e36eKbOFS9QLpX6xDzeiLou1RS06Lpw66ukD5MdsPJrooIiuleD_2KjEMfXjF0PRRn3khk0smi1ze4C7P1HCzWplXosG4OMSw_zeyBgVSDp3WNv7rHfOIFlt9vSjLk0BmdwhV5a61IA948txJQyMRmTAtXy06C7enSQ39S6DQiNPolCtHvJkqdkYE2A8nlQyVt-aeRUgwFPqXdlBXSwfe5E9FB5Pyis1OJykwxXM6b3e_VzoP6sCYH-8TO_3C38W-XHuiWVAnQdnc673HEK0j8evKMNotnjEJf4hLqsae4ufmJNOiOXdgANZL-gxdSllX7HVWh1H2pJk9clAI8ZhL0fe9qTMTrtpCoypc7jF_5tAyQFKnxI632cHHyjedVByA9Nog-a3_rqduMTmsvc8km4bo-ss1u84L_DrS4IrYoJnP3sEiRgI8dMDwHvwpaNm51tvVIY9oLBRRg3UFYxvq-TaR69WVatkgd2ilPFIu_818tTzjsopF95PBlV_09qurHSGMnH3nKq7tjqSlprgG3vZiKxHgsaikbjvpzdOnU8sSdtsO74HjmRyf4FmA
export const listCompany = async (data) => {
try {
const res = await axios.post(http://myserver:8000/collect_review/public/index.php/api/company/list
,
null,
{ headers:{
‘Authorization’: Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiJ9.eyJhdWQiOiIxIiwianRpIjoiMzEyNzc2ZmFiZGQyYjllYTBiMWM1ODRjNmI0Mzg2NzQ5YmVlY2YwM2ZlMGIwOGE4NDgxMmFkYmRlNDcyZDNiNTE3NjkxY2RmOGNiYjQzNTAiLCJpYXQiOjE3MTM3NjQxMzIuNjEwMjM3LCJuYmYiOjE3MTM3NjQxMzIuNjEwMjQzLCJleHAiOjE3NDUzMDAxMzIuNTk2Njc2LCJzdWIiOiIxNSIsInNjb3BlcyI6W119.ejjZExqN7EhoXAp0p_wUeBVq6gzQlOGBNzAhmbXyKzCzVdL5pw5BcySlns1K2rLn5KoyVU8kw_-VJfT3RWe_UB83uakzz47-w1fd2a89NpwIY1e36eKbOFS9QLpX6xDzeiLou1RS06Lpw66ukD5MdsPJrooIiuleD_2KjEMfXjF0PRRn3khk0smi1ze4C7P1HCzWplXosG4OMSw_zeyBgVSDp3WNv7rHfOIFlt9vSjLk0BmdwhV5a61IA948txJQyMRmTAtXy06C7enSQ39S6DQiNPolCtHvJkqdkYE2A8nlQyVt-aeRUgwFPqXdlBXSwfe5E9FB5Pyis1OJykwxXM6b3e_VzoP6sCYH-8TO_3C38W-XHuiWVAnQdnc673HEK0j8evKMNotnjEJf4hLqsae4ufmJNOiOXdgANZL-gxdSllX7HVWh1H2pJk9clAI8ZhL0fe9qTMTrtpCoypc7jF_5tAyQFKnxI632cHHyjedVByA9Nog-a3_rqduMTmsvc8km4bo-ss1u84L_DrS4IrYoJnP3sEiRgI8dMDwHvwpaNm51tvVIY9oLBRRg3UFYxvq-TaR69WVatkgd2ilPFIu_818tTzjsopF95PBlV_09qurHSGMnH3nKq7tjqSlprgG3vZiKxHgsaikbjvpzdOnU8sSdtsO74HjmRyf4FmA
,
‘Accept’: ‘application/json’,
‘Content-Type’: ‘application/json’,
}})
console.log(res)
return res
}
catch (err) {
return err
}
}
Ritesh Maurya is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
The 401 Unauthorized status code indicates that the request has not been applied because it lacks valid authentication credentials for the target resource. In this case, it seems that the request is trying to access a resource with a bearer token in the Authorization header, but it’s being rejected.
Here are a few things you can check to troubleshoot this issue:
-
Check Token Validity: Ensure that the bearer token (
eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiJ9...
) included in the Authorization header is valid and has not expired. -
Correct Header Format: Verify that the Authorization header is properly formatted. It should be
Authorization: Bearer <token>
where<token>
is the actual token. -
Token Scope: Make sure that the bearer token has the necessary permissions to access the resource. The server might be rejecting the request if the token lacks the required scope.
-
Server Configuration: Check the server configuration to ensure that it is correctly configured to validate bearer tokens. There might be misconfigurations or issues with the server setup causing the authentication failure.
-
Debugging Output: Use debugging tools or enable detailed logging on both the client and server sides to get more information about why the authentication is failing.
-
Network Issues: Sometimes, network issues can cause authentication failures. Ensure that there are no network connectivity issues between the client and server.
By checking these points, you should be able to identify and resolve the authentication issue. Let me know if you need further assistance!
Ateeb Ur Rahmaan is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.