MCPcopy Create free account
hub / github.com/CoderOpen/waimai / guzzleRequest

Method guzzleRequest

app/Http/Services/Net/Curl.php:73–102  ·  view source on GitHub ↗

* 简单请求数据 */

($url, $params, $timeout, $headers = [])

Source from the content-addressed store, hash-verified

71 * 简单请求数据
72 */
73 static function guzzleRequest($url, $params, $timeout, $headers = [])
74 {
75 $client = new \GuzzleHttp\Client(['timeout' => $timeout, 'headers' => $headers, 'http_errors' => false,]);
76 try {
77 $data = [];
78 if ($headers) {
79 $data['headers'] = $headers;
80 }
81 $jar = new \GuzzleHttp\Cookie\CookieJar;
82 $data['cookies'] = $jar;
83 if (!$params) {
84 $response = $client->request('GET', $url, $data);
85 } else {
86 $data = array_merge($data, $params);
87 $response = $client->request('POST', $url, $data);
88 }
89 $body = $response->getBody();
90 if ($body instanceof Stream) {
91 $body = $body->getContents();
92 }
93 $res = json_decode($body, true);
94 if ($res) {
95 return $res;
96 }
97 return $body;
98 } catch (\GuzzleHttp\Exception\GuzzleException $e) {
99 echo $e->getTraceAsString();
100 return false;
101 }
102 }
103
104 /**
105 * query必填成参数

Callers

nothing calls this directly

Calls 1

requestMethod · 0.80

Tested by

no test coverage detected