🔥码云GVP开源项目 12k star Uniapp+ElementUI 功能强大 支持多语言、二开方便! 广告
# HTTP ## 使用Guzzle库 魔工海豚内置了Guzzle http://guzzle-cn.readthedocs.io/zh_CN/latest/ ## 使用原生php发送http ``` $jsonStr = json_encode(array( 'body' => "{'name':'My First Conversation','m': ['{$user['id']}', '{$at_user['id']}']}" )); public function http_post_json($url, $jsonStr) { $ch = curl_init(); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_POSTFIELDS, $jsonStr); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_HTTPHEADER, array( 'X-LC-Id:'.config('X-LC-Id'), 'X-LC-Key:'.config('X-LC-Key'), 'Content-Type: application/json; charset=utf-8', 'Content-Length: ' . strlen($jsonStr) ) ); $response = curl_exec($ch); $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE); return array($httpCode, $response); } list($returnCode, $returnContent) = $this->http_post_json($url, $jsonStr); // returnCode 状态码 // returnContent 返回内容 ```