with http domain, it works, returning the expected output but with https, headers are null. Below is my attempt.
POST CURL
$fields = [];
$headers = ['_token: 58SkLjsNMk0', 'Authorization: 6059DLaf39d4141' ];
$cURLConnection = curl_init('<https domain>/api/auth/check');
curl_setopt($cURLConnection, CURLOPT_POSTFIELDS, $fields);
curl_setopt($cURLConnection, CURLOPT_HTTPHEADER,$headers);
curl_setopt($cURLConnection, CURLOPT_RETURNTRANSFER, true);
$res = curl_exec($cURLConnection);
curl_close($cURLConnection);
dd($res);
Middleware
<?php
namespace App\Http\Middleware;
use Closure;
class Api
{
/**
* Handle an incoming request.
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @return mixed
*/
public function handle($request, Closure $next){
return response()->json($request->header('Authorization'));
}
}
Any help, suggestions is greatly appreciated. Thanks in advance.
Maybe the HTTPS version has some 30x redirect in it? Try adding curl_setopt($cURLConnection, CURLOPT_FOLLOWLOCATION, true);
to make cURL follow the redirection.
Also, just for debugging purposes(,), please try to add -
curl_setopt($cURLConnection, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($cURLConnection, CURLOPT_SSL_VERIFYPEER, false);
These well disable the verification of the certificate's name against host / the peer's SSL certificate. (Add them all before curl_exec()
)
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.