我正在使用laravel框架。 我正在尝试使用api更新现有数据(有点新的)。
所以这是我的路线
Route::group(['middleware' => 'web'], function () {
Route::post('/update_supplier_details/{id}', "UpdateController@update_supplier_details");
});
这是我的控制器
public function update_supplier_details(Request $request, $id){
$details = $request->all();
$client = new CharmeAPI;
$token = Session::get('token');
$url = "https://api.charmeapp.com/api/v1/suppliers/{$id}?token={$token}";
$response = $client->request('POST', $url,['form_params' => $details])->getBody();
echo $response;
$data = json_decode($response, true);
$status = array_get($data, 'status');
$message = array_get($data, 'error.msg');
if($status == 'error'){
session(['update_supplier_details_error' => $status]);
return redirect()->back()->with('supplier_details_msg', $message);
}
else if($status == 'ok') {
session(['update_supplier_details_error' => $status]);
session(['supplier_details_first_name' => array_get($data, 'data.Supplier.first_name')]);
session(['supplier_details_last_name' => array_get($data, 'data.Supplier.last_name')]);
$first_name = session('supplier_details_first_name');
$last_name = session('supplier_details_last_name');
return $first_name.$last_name;
return redirect()->back()->with('supplier_details_msg', $first_name.' '.$last_name.' added successfully');
}
}
}
我收到此错误 -
RequestException.php第107行中的ServerException: 服务器错误:POST https://api.charmeapp.com/api/v1/suppliers/139?token=Q8vJLPvpnRImoz5Li4tVfGtGliyGBQcx3NdqYbNdRaYYvsaoLncyDvFHkriS导致500内部服务器错误响应:
<!DOCTYPE html>
<html>
<head>
<meta name="robots" content="noindex,nofollow" />
<style>
(truncated...)
但如果我使用postman来调用api url,我会得到所需的数据 任何帮助请
答案 0 :(得分:0)
确保将正确的参数和令牌传递给api。