Loading src/Tools/HttpRequestJson.php +17 −18 Original line number Diff line number Diff line Loading @@ -19,13 +19,14 @@ namespace Meibuyu\Micro\Tools; class HttpRequestJson { protected static function prepareRequest(&$headers = [], &$data = []) protected static function prepareRequest($headers, $data = []) { $data = json_encode($data); if (!$data) { if (!empty($data)) { $headers['Content-type'] = 'application/json'; $headers['Content-Length'] = strlen($data); } return [$headers, $data]; } // /** Loading @@ -43,27 +44,27 @@ class HttpRequestJson // /** // * post请求 // * @param $url // * @param $dataArray // * @param $data // * @param array $httpHeaders // * @return ResponseInterface // */ // public static function post($url, $dataArray, $httpHeaders = []) // public static function post($url, $data, $httpHeaders = []) // { // $client = new Client(['timeout' => 30]); // return $client->post($url, ['headers' => $httpHeaders, 'json' => $dataArray]); // return $client->post($url, ['headers' => $httpHeaders, 'json' => $data]); // } // // /** // * put请求 // * @param $url // * @param $dataArray // * @param $data // * @param array $httpHeaders // * @return ResponseInterface // */ // public static function put($url, $dataArray, $httpHeaders = []) // public static function put($url, $data, $httpHeaders = []) // { // $client = new Client(['timeout' => 30]); // return $client->put($url, ['headers' => $httpHeaders, 'json' => $dataArray]); // return $client->put($url, ['headers' => $httpHeaders, 'json' => $data]); // } // // /** Loading @@ -86,34 +87,33 @@ class HttpRequestJson */ public static function get($url, $headers = []) { self::prepareRequest($headers); return CurlRequest::get($url, $headers); } /** * post请求 * @param $url * @param $dataArray * @param $data * @param array $headers * @return array */ public static function post($url, $dataArray, $headers = []) public static function post($url, $data, $headers = []) { self::prepareRequest($headers, $dataArray); return CurlRequest::post($url, $dataArray, $headers); [$headers, $data] = self::prepareRequest($headers, $data); return CurlRequest::post($url, $data, $headers); } /** * put请求 * @param $url * @param $dataArray * @param $data * @param array $headers * @return array */ public static function put($url, $dataArray, $headers = []) public static function put($url, $data, $headers = []) { self::prepareRequest($headers, $dataArray); return CurlRequest::put($url, $dataArray, $headers); [$headers, $data] = self::prepareRequest($headers, $data); return CurlRequest::put($url, $data, $headers); } /** Loading @@ -124,7 +124,6 @@ class HttpRequestJson */ public static function delete($url, $headers = []) { self::prepareRequest($headers); return CurlRequest::delete($url, $headers); } Loading Loading
src/Tools/HttpRequestJson.php +17 −18 Original line number Diff line number Diff line Loading @@ -19,13 +19,14 @@ namespace Meibuyu\Micro\Tools; class HttpRequestJson { protected static function prepareRequest(&$headers = [], &$data = []) protected static function prepareRequest($headers, $data = []) { $data = json_encode($data); if (!$data) { if (!empty($data)) { $headers['Content-type'] = 'application/json'; $headers['Content-Length'] = strlen($data); } return [$headers, $data]; } // /** Loading @@ -43,27 +44,27 @@ class HttpRequestJson // /** // * post请求 // * @param $url // * @param $dataArray // * @param $data // * @param array $httpHeaders // * @return ResponseInterface // */ // public static function post($url, $dataArray, $httpHeaders = []) // public static function post($url, $data, $httpHeaders = []) // { // $client = new Client(['timeout' => 30]); // return $client->post($url, ['headers' => $httpHeaders, 'json' => $dataArray]); // return $client->post($url, ['headers' => $httpHeaders, 'json' => $data]); // } // // /** // * put请求 // * @param $url // * @param $dataArray // * @param $data // * @param array $httpHeaders // * @return ResponseInterface // */ // public static function put($url, $dataArray, $httpHeaders = []) // public static function put($url, $data, $httpHeaders = []) // { // $client = new Client(['timeout' => 30]); // return $client->put($url, ['headers' => $httpHeaders, 'json' => $dataArray]); // return $client->put($url, ['headers' => $httpHeaders, 'json' => $data]); // } // // /** Loading @@ -86,34 +87,33 @@ class HttpRequestJson */ public static function get($url, $headers = []) { self::prepareRequest($headers); return CurlRequest::get($url, $headers); } /** * post请求 * @param $url * @param $dataArray * @param $data * @param array $headers * @return array */ public static function post($url, $dataArray, $headers = []) public static function post($url, $data, $headers = []) { self::prepareRequest($headers, $dataArray); return CurlRequest::post($url, $dataArray, $headers); [$headers, $data] = self::prepareRequest($headers, $data); return CurlRequest::post($url, $data, $headers); } /** * put请求 * @param $url * @param $dataArray * @param $data * @param array $headers * @return array */ public static function put($url, $dataArray, $headers = []) public static function put($url, $data, $headers = []) { self::prepareRequest($headers, $dataArray); return CurlRequest::put($url, $dataArray, $headers); [$headers, $data] = self::prepareRequest($headers, $data); return CurlRequest::put($url, $data, $headers); } /** Loading @@ -124,7 +124,6 @@ class HttpRequestJson */ public static function delete($url, $headers = []) { self::prepareRequest($headers); return CurlRequest::delete($url, $headers); } Loading