所以,我目前在 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/