websocket连接后,发送数据;接收数据全是400,bad request
来源:4-7 websocket服务案例实现(上)
慕工程4824230
2018-07-09
//代码片段 $json_send_data = "{'event':'ping'}"; if (!$client->send($json_send_data)) { die("send failed."); } //从服务器接收数据 $data = $client->recv(); //var_dump($data);die; if (!$data) { die("recv failed."); } echo $data;
老师,这是什么情况?
写回答
2回答
-
慕工程4824230
提问者
2018-07-10
<?php /** * Created by PhpStorm. * User: Administrator * Date: 2018/7/9/009 * Time: 12:31 */ //建立连接 $client = new swoole_client(SWOOLE_SOCK_TCP); $api_url = 'api.huobi.br.com'; //$api_url = 'api.hadax.com'; $port = 443; //连接到服务器 wss://api.hadax.com/ws if (!$client->connect($api_url, $port, -1)) { die("connect failed."); } //向服务器发送数据 $send_data = [ "req"=> "market.btcusdt.kline.1min", // "sub"=> "market.btcusdt.kline.1min", "id"=> "id" ]; //$send_data = ['ping'=> 123456789]; $json_send_data = json_encode($send_data); var_dump($json_send_data); $client->send($json_send_data); //从服务器接收数据 $data = $client->recv(); //var_dump($data);die; if (!$data) { die("recv failed."); } echo $data; //关闭连接 $client->close();
老师,代码附上了;顺便求老师告知下QQ,我的是346025425
ws地址原始的为: wss://api.huobi.br.com/ws,我填写连接不上,然后我就只用了api.huobi.br.com
00 -
singwa
2018-07-10
你整体的代码打包能发我吗?我看看整体的
022018-07-10