【问题标题】:ServerException in RequestException.php line 107: 500 Internal Server ErrorRequestException.php 第 107 行中的 ServerException:500 内部服务器错误
【发布时间】:2016-09-20 07:07:39
【问题描述】:

我正在使用 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 Internal Server Error 响应:

<!DOCTYPE html>
<html>
<head>
<meta name="robots" content="noindex,nofollow" />
<style>

(truncated...)

但是,如果我使用邮递员调用 api url,我会得到所需的数据 任何帮助请

【问题讨论】:

  • 你需要找出服务器错误是什么。为您的应用程序启用调试(在 .env 文件上使用 APP_DEBUG=true,确保在完成调试后将其更改回 false,因为您为此使用的是实时应用程序)。在您的浏览器上,使用开发人员工具查看错误消息。如果找不到解决方案,请在此处发布以寻求帮助。
  • @crabbly 我就是这样做的,我收到了这个错误消息localhost/charme_admin/public/update_customer_details/154 加载资源失败:服务器响应状态为 500(内部服务器错误)
  • 呃,我也需要这个问题的答案。你有想过吗?
  • @cora 是的,我做到了。确保将正确的参数和令牌传递给 api。

标签: php laravel guzzle


【解决方案1】:

确保将正确的参数和令牌传递给 api。

【讨论】:

    猜你喜欢
    • 2017-02-03
    • 1970-01-01
    • 2019-01-17
    • 2011-10-17
    • 2010-11-15
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多