'Array to string conversion error in header
Currently working with laravel 8.And calling the api using httpclient but few of them i need to pass the bearer token in headers for which struggling from couple of hours seems like didn't work anything.
Any help will be appreciated. Thanks,
try {
$token = array(Session::get('access_token'));
$headers = [
'Authorization' => 'Bearer ' . $token,
'Accept' => 'application/json',
];
// echo "<pre>"; print_r($token); die();
if ( $data != null ) {
$response = Http::withHeaders($headers)->asForm()->post($endpoint, $data);
}else{
$response = Http::get($endpoint);
}
$result = $response->json();
echo "<pre>"; print_r($result);die();
$httpcode = $response->status();
$error_msg = ($response->serverError()) ?? '';
// echo "<pre>"; print_r($result);die();
if ( $error_msg == '' ) {
$response = [ 'status' => true, 'result' => $result, 'status_code' => $httpcode ];
return $response ;
} else {
return [ 'status' => false, 'result' => [], 'status_code' => $httpcode, 'error' => $error_msg ];
}
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|