1.在linux下通过curl直接请求ok
2.把代码里面的地址换成ip,请求正常
3.代码如下:
private function post($url, $data, $timeout = 3) { $jsonData = json_encode($data); $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_TIMEOUT, $timeout); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); curl_setopt($ch, CURLOPT_HTTPHEADER, ['Content-Type: application/json;Charset=utf-8','Content-Length :'.strlen($jsonData)]); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, $jsonData); $resp = curl_exec($ch); if ($resp === false) { Yii::info('resp err:'.curl_error($ch)); curl_close($ch); return []; } curl_close($ch); return json_decode($resp, true); }
研究了半天,不知道哪有问题,一直无法解析域名。服务器是阿里云的,对方服务器是腾讯云.哪位大神指导一下。
UYOU