controller PagesController
public function index()
{
$client = new Client();
$hospital_id = 37;
$res = $client->request('POST', 'http://vph.com/api/GetService'.$hospital_id,[
'form_params' => [
'body'=>$hospital_id
]
]);
我想api命中但是没有工作
错误
Client error: `POST http://vpshealth.com/api/GetServiceList37` resulted in a `404 Not Found` response: <html> <head><title>404 Not Found</title></head> <body bgcolor="white"> <center><h1>404 Not Found</h1></center> <hr> (truncated...)
答案 0 :(得分:1)
网址
中缺少 /网址应为 http://vph.com/api/GetService/'。$ hospital_id
<div class="form-group name-first">
<input class="form-control" type="text" placeholder="First Name">
</div>
<div class="form-group name-last">
<input class="form-control" type="text" placeholder="Last Name">
</div>
<div class="form-group">
<input class="form-control" type="email" placeholder="Email">
</div>
<div class="form-group password">
<input class="form-control" type="password" placeholder="Password">
</div>
<div class="form-group password-confirm">
<input class="form-control" type="password" placeholder="Confirm Password">
</div>
<div class="form-group">
<input class="form-control btn btn-alternative" type="submit" value="Register">
</div>
答案 1 :(得分:0)
public function index()
{
$client = new Client();
$hospital_id = 37;
$res = $client->request('POST', 'http://vpshealth.com/api/GetServiceList?hospital_id'.$hospital_id,[
'form_params' => [
'body'=>$hospital_id
]
]);
所有更改都将完成但错误相同
答案 2 :(得分:0)
$client = new \GuzzleHttp\Client();
$hospital_id = 37;
$response = $client->request("POST", "http://vpshealth.com/api/GetServiceList?hospital_id=".$hospital_id,
[
'json'=>['body'=>$hospital_id]
]);
$data=$response->getbody();
$data=json_decode($data);
dd($data);
<强>解决强>