我正在尝试与远程服务器建立 websocket 连接并收到以下错误:WebSocket 握手被远程对等方拒绝
我正在关注这个例子:https : //www.boost.org/doc/libs/1_70_0/libs/beast/example/websocket/client/sync/websocket_client_sync.cpp
对于以下服务器:https : //api.hitbtc.com/#socket-api-reference
提前感谢您的帮助!
int main(int argc, char** argv) {
try
{
auto const host = "api.hitbtc.com";
auto const port = "443";
net::io_context ioc;
tcp::resolver resolver{ ioc };
websocket::stream<tcp::socket> ws{ ioc };
auto const results = resolver.resolve(host, port);
net::connect(ws.next_layer(), results.begin(), results.end());
// Perform the websocket handshake - this is where i presume the issue is.
ws.handshake(host, "/api/2/ws");
beast::flat_buffer buffer;
ws.read(buffer);
ws.close(websocket::close_code::normal);
std::cout << beast::make_printable(buffer.data()) << std::endl;
}
catch (std::exception const& e) …Run Code Online (Sandbox Code Playgroud)