From 5d3781fce0a4a562d4351bcb6216841b1797b546 Mon Sep 17 00:00:00 2001 From: Mars Lee <285753421@qq.com> Date: Tue, 12 Dec 2017 15:51:06 +0800 Subject: [PATCH] fixed curl header error --- application/home/controller/debug.php | 167 +++++++++++++------------- 1 file changed, 86 insertions(+), 81 deletions(-) diff --git a/application/home/controller/debug.php b/application/home/controller/debug.php index 5653473..5b9a230 100644 --- a/application/home/controller/debug.php +++ b/application/home/controller/debug.php @@ -10,134 +10,139 @@ use gophp\response; class debug extends controller { - // 获取接口id - public function index() - { - $api = request::post('api', []); - $request = request::post('request', []); + // 获取接口id + public function index() + { + $api = request::post('api', []); + $request = request::post('request', []); + $headers = request::post('header', []); - if(!$url = $api['url']){ + if(!$url = $api['url']){ - response::ajax(['code'=> 300, 'msg' => '请求地址不存在']); + response::ajax(['code'=> 300, 'msg' => '请求地址不存在']); - } + } - if(!$method = $api['method']){ + if(!$method = $api['method']){ - response::ajax(['code'=> 300, 'msg' => '请求方式不存在']); + response::ajax(['code'=> 300, 'msg' => '请求方式不存在']); - } + } - $data = []; + $data = []; + $http_header = []; + foreach ($headers as $k=>$v){ + foreach ($v as $k1=>$v1){ + $http_header[] = $request['key'][$k1].': '.$v1; + } + } + foreach ($request as $k=>$v){ + foreach ($v as $k1=>$v1){ + $data[$request['key'][$k1]] = $v1; + } + } - foreach ($request as $k=>$v){ - foreach ($v as $k1=>$v1){ - $data[$request['key'][$k1]] = $v1; - } - } + $curl = new curl($url, $method, $data, $http_header); - $curl = new curl($url, $method, $data); + if($info = $curl->getInfo()){ - if($info = $curl->getInfo()){ + $info = serialize($info); - $info = serialize($info); + } - } + if($body = $curl->getBody()){ + $body = serialize($body); + } - if($body = $curl->getBody()){ - $body = serialize($body); - } + if($header = $curl->getHeader()){ + $header = serialize($header); + } + + response::ajax(['info' => $info,'header' => $header,'body' => $body]); - if($header = $curl->getHeader()){ - $header = serialize($header); } - response::ajax(['info' => $info,'header' => $header,'body' => $body]); + public function load() + { - } + $info = request::post('info', ''); + $header = request::post('header', ''); + $body = request::post('body', ''); - public function load() - { + if($info){ - $info = request::post('info', ''); - $header = request::post('header', ''); - $body = request::post('body', ''); + $this->assign('info', unserialize($info)); - if($info){ + } - $this->assign('info', unserialize($info)); + if($header){ - } + $this->assign('headers', unserialize($header)); - if($header){ + } - $this->assign('headers', unserialize($header)); + if($body){ - } + $this->assign('body', unserialize($body)); - if($body){ + } - $this->assign('body', unserialize($body)); + $this->display('debug/load'); } - $this->display('debug/load'); - - } - - // 获取接口详情 - public function __call($name, $arguments) - { + // 获取接口详情 + public function __call($name, $arguments) + { - $id = id_decode($this->action); + $id = id_decode($this->action); - $api = api::get_api_info($id); + $api = api::get_api_info($id); - if(!$api){ + if(!$api){ - $this->error('该接口不存在'); + $this->error('该接口不存在'); - } + } - $project = api::get_project_info($id); + $project = api::get_project_info($id); - // 获取项目环境域名 - $envs = json_decode($project['envs'], true); + // 获取项目环境域名 + $envs = json_decode($project['envs'], true); - foreach ($envs as $k => $env) { - $envs[$k]['name'] = $env['name']; - $envs[$k]['title'] = $env['title']; - $envs[$k]['url'] = $env['domain'] . '/' . $api['uri']; - } + foreach ($envs as $k => $env) { + $envs[$k]['name'] = $env['name']; + $envs[$k]['title'] = $env['title']; + $envs[$k]['url'] = $env['domain'] . '/' . $api['uri']; + } - $encode_id = id_encode($api['id']); + $encode_id = id_encode($api['id']); - $mock = [ - 'name' => 'mock', - 'title' => '虚拟地址', - 'url' => url("mock/$encode_id", '', true), - ]; + $mock = [ + 'name' => 'mock', + 'title' => '虚拟地址', + 'url' => url("mock/$encode_id", '', true), + ]; - sort($envs); - array_push($envs, $mock); + array_unshift($envs, $mock); - // 获取请求参数列表 - $request_fields = \app\field::get_field_list($id, 1); + // 获取请求参数列表 + $request_fields = \app\field::get_field_list($id, 1); - // 获取header参数列表 - $header_fields = \app\field::get_field_list($id, 3); + // 获取header参数列表 + $header_fields = \app\field::get_field_list($id, 3); - $methods = \app\api::get_method_list(); + $methods = \app\api::get_method_list(); - $this->assign('api', $api); - $this->assign('envs', $envs); - $this->assign('methods', $methods); + $this->assign('api', $api); + $this->assign('envs', $envs); + $this->assign('methods', $methods); - $this->assign('request_fields', $request_fields); - $this->assign('header_fields', $header_fields); + $this->assign('request_fields', $request_fields); + $this->assign('header_fields', $header_fields); - $this->display('debug/detail'); + $this->display('debug/detail'); - } + } } \ No newline at end of file -- Gitee