客户端错误:
GET http://127.0.0.1:8000/api/groups
导致404 Not Found
回复:
每当我尝试从API获取数据时,都会显示此错误,但是当我尝试从API获取相同数据时,它将完美显示所有数据
这是API代码 控制器:
$mat_cens = \DB::SELECT('SELECT * FROM dbo.Master1 WHERE MasterType = 11');
return response()->json(['mat_cens'=>$mat_cens]);
中间件:
$token = $request->header('App_KEY');
if($token != 'QAWLhIK2p5'){
return response()->json(['message'=>'Unauthorized'], 401);
}
else{
return $next($request)
->header('Access-Control-Allow-Origin', '*')
->header('Access-Control-Allow-Methods', 'GET, POST, PUT, DELETE, OPTIONS')
->header('Access-Control-Allow-Headers', 'X-Requested-With, Content-Type, X-Token-Auth, Authorization');
}
这是我想要API数据的应用代码
控制器:
$client = new Client();
$body['headers'] = array('APP_KEY'=>'QAWLhIK2p5');
$response = $client->request('GET','http://127.0.0.1:8000/api/groups',$body);
dd($response->getStatusCode());
$data = $response->getBody();
dd(json_decode($data));
请帮助我解决此问题 任何帮助将不胜感激.......