Galan Lucian
Galan Lucian

Reputation: 103

How to get data from a node.js server using a http reqest with SFML in C++?

So, the code I currently have in C++ is:

#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;
}

And I've created a local server using node.js and I'd like to get the json data. The code above doesn't work and I don't know what to do. The error code I get is 1001 (ConnectionFailed).

Any ideas?

Upvotes: 0

Views: 98

Answers (1)

Botje
Botje

Reputation: 30907

I think you're using the sf::Http constructor wrong.

The constructor calls setHost which does not parse port numbers. You need to explicitly pass the port number as follows:

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

Upvotes: 2

Related Questions