WebSocket を使用して Watson Speech to Text サーバーに接続しようとしていますが、接続しようとしても接続しません。websocket接続を認証するための接続トークンを取得したので、URLと連結して接続を試みますが、befireが接続しないと言ったように、誰かが私を助けてくれますか?
前もって感謝します。
これは私のコードです:
#include <cpprest/ws_client.h>
#include <cpprest/http_client.h>
#include <cpprest/filestream.h>
#include <iostream>
#include <sstream>
#include <fstream>
using namespace web;
using namespace web::websockets;
using namespace web::websockets::client;
using namespace web::http;
using namespace web::http::client;
#include <cpprest/http_client.h>
#include <cpprest/filestream.h>
using namespace utility; // Common utilities like string conversions
using namespace web; // Common features like URIs.
using namespace web::http; // Common HTTP functionality
using namespace web::http::client; // HTTP client features
using namespace concurrency::streams; // Asynchronous streams
int main(int argc, char* argv[]){
auto fileStream = std::make_shared<ostream>();
// Open stream to output file.
pplx::task<void> requestTask = fstream::open_ostream(U("../data/token.txt")).then([=](ostream outFile)
{
*fileStream = outFile;
// Create http_client to send the request.
http_client_config config;
// Build request URI and start the request.
credentials cred(L"******-****-****-****-************", L"************");
config.set_credentials(cred);
http_client client(U("https://stream.watsonplatform.net"), config);
uri_builder builder(U("/authorization/api/v1/token?url=https://stream.watsonplatform.net/speech-to-text/api"));
return client.request(methods::GET, builder.to_string());
})
// Handle response headers arriving.
.then([=](http_response response)
{
//printf("Received response status code:%u\n", response.status_code());
// Write response body into the file.
return response.body().read_to_end(fileStream->streambuf());
})
// Close the file stream.
.then([=](size_t)
{
return fileStream->close();
});
// Wait for all the outstanding I/O to complete and handle any exceptions
try
{
requestTask.wait();
}
catch (const std::exception &e)
{
printf("Error exception:%s\n", e.what());
}
//Ler arquivo e guardar token//////
std::ifstream file;
std::string token;
file.open("../data/token.txt");
file >> token;
std::string url = "wss://stream.watsonplatform.net/speech-to-text/api/v1/recognize?watson-token=" + token + "&model=pt-BR_BroadbandModel";
uri wsUrl(conversions::to_string_t(url));
websocket_client wsclient;
wsclient.connect(wsUrl).wait();
}