首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >如何修复guzzlehttp截断的500内部服务器错误代码点火器

如何修复guzzlehttp截断的500内部服务器错误代码点火器
EN

Stack Overflow用户
提问于 2019-08-01 11:30:03
回答 1查看 470关注 0票数 0

我想让web rest客户端使用Guzzle,但出现错误"500内部服务器错误“

我尝试使用$client = new \GuzzleHttp\Client();但是没有任何变化

这是我的控制器

代码语言:javascript
复制
public function __construct()
{
    parent::__construct();
    $this->load->model('model_regis');
    $this->load->library('form_validation');

}

public function index(){
    $username   = $this->input->post('namaDaftar');
    $email      = $this->input->post('emailDaftar');
    $nomor      = $this->input->post('nomorDaftar');
    $password   = $this->input->post('passwordDaftar');

    $this->model_regis->add($username,$email,$password,$nomor);

    redirect(base_url());
}



/*public function tambah(){
    $this->load->view('form_login');
}*/

public function guzzle_get($url,$uri){
    $client = new GuzzleHttp\Client(['base_uri' => $url]);
    $response = $client->request('POST',$uri);
    return $response->getBody()->getContents();
}

我的模型

代码语言:javascript
复制
public function __construct(){

    /*$this->_client = new Client([
        'base_uri' => 'http://malltik.com/malltik_api/user'
    ]);*/
}

public function add($username, $email, $password, $nomor){

        $client = new \GuzzleHttp\Client();

        $data = array(
            'user_nama' => $username,
            'user_email' => $email,
            'user_pass' => $password,
            'user_number' => $nomor,
            );

        $response = $client->request('POST', 'http://malltik.com/malltik_api/user/registrasi', [
            'form_params' => $data
        ]);

        $result = json_decode($response->getBody()->getContent(), true);

        return $result;
    }

我想在rest api上创建一个注册函数

EN

Stack Overflow用户

发布于 2020-01-24 20:25:32

我也有同样的问题,在互联网上搜索,我找到了一个简单的解决方案。

首先,您必须捕获异常,然后显示其内容。

代码语言:javascript
复制
$client = new GuzzleHttp\Client(['base_uri' => $this->url]);
try {
    $response = $client->request('POST', '');
    return $response->getBody();
} catch (GuzzleHttp\Exception\BadResponseException $e) {
    return $e->getResponse()->getBody()->getContents();
}

我希望这段代码能对你有所帮助。

票数 0
EN
查看全部 1 条回答
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/57301449

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档