ThinkChat2.0新版上线,更智能更精彩,支持会话、画图、视频、阅读、搜索等,送10W Token,即刻开启你的AI之旅 广告
~~~ /** * * * 发送HTTP请求(默认是POST请求) * * @author guoguangyang * * @param string $url * 请求URL * @param array $data * 请求数据 * @param array $headers * 头部信息 * @param string $method * 请求方式 * @throws Exception * * @return string */ public static function httpRequest($url, $data, $headers = array(), $method = 'POST') { try { $client = new Zend_Http_Client($url, array( 'keepalive' => false, 'timeout' => 30 )); if (! empty($headers)) { $client->setHeaders($headers); } $method == 'POST' ? $client->setParameterPost($data) : $client->setParameterGet($data); $response = $client->request($method == 'POST' ? 'POST' : ''); if ($response->isSuccessful()) { $result = $response->getBody(); } else { throw new Exception($response->getMessage(), $response->getStatus()); } } catch (Zend_Http_Client_Exception $e) { $result = 'Code:' . $e->getCode() . '--Message:' . $e->getMessage(); } return $result; } ~~~