c++ - 如何在 C++ 中使用带有 SFML 的 http 请求从 node.js 服务器获取数据?

标签 c++ node.js http server sfml

所以,我目前在 C++ 中的代码是:

#include <SFML/Network.hpp>
#include <iostream>

int main()
{
    // prepare the request
    sf::Http::Request request("/", sf::Http::Request::Get);

    // send the request
    sf::Http http("http://localhost:3000/");
    sf::Http::Response response = http.sendRequest(request);

    // check the status
    std::cout << response.getStatus();

    return 0;
}

我创建了一个 local server使用 node.js,我想获取 json 数据。 上面的代码不起作用,我不知道该怎么做。我得到的错误代码是 1001 (ConnectionFailed)。

有什么想法吗?

最佳答案

我认为您错误地使用了 sf::Http 构造函数。

构造函数调用setHost它不解析端口号。您需要显式传递端口号,如下所示:

sf::Http http("http://localhost", 3000);

关于c++ - 如何在 C++ 中使用带有 SFML 的 http 请求从 node.js 服务器获取数据?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59324967/

相关文章:

c++ - 如何让Boost::random和Matlab产生相同的随机数

c++ - 我如何将 std::cin.getline() 与字符串一起使用

javascript - Nodejs - SolrClient,如何等待响应

java - Http 响应内容类型为 json。 "Invalid mime type"错误

http - 无法获得摘要身份验证以使用 node.js

c++ - 如何在 Boost Unit 中正确定义派生单位

c++ - 使用属性树在 Boost 中创建 JSON 数组

node.js - 等待不是等待

node.js - AWS SQS 和 SNS 中的消息结构

http - 将服务请求重定向到另一台服务器