Hi,
I've never used a REST API before but I'd like to get introduced to them.
I wanted to learn what they are and how to use them so I've picked up one for testing its functionalities. I found this
https://www.themoviedb.org/ movie database that provides some interesting functions. I learned how to use those functions on my browser with urls like "
http://api.themoviedb.org/3/discover/movie?api_key=###" and know I'd like to use those methods on a c++ program.
I found the sfml tutorial
http://www.sfml-dev.org/tutorials/2.3/network-http.php that if I'm not wrong explains how to do it, however there's something I'm doing wrong:
I followed the tutorial and wrote this:
#include <iostream>
#include <SFML/Network.hpp>
int main() {
sf::Http http("http://api.themoviedb.org/3/");
sf::Http::Request request;
request.setMethod(sf::Http::Request::Get);
request.setUri("/movie/popular");
sf::Http::Response response = http.sendRequest(request);
std::cout << "status: " << response.getStatus() << std::endl;
std::cout << "HTTP version: " << response.getMajorHttpVersion() << "." << response.getMinorHttpVersion() << std::endl;
std::cout << "Content-Type header:" << response.getField("Content-Type") << std::endl;
std::cout << "body: " << response.getBody() << std::endl;
return 0;
}
The status response is always 1001 witch means "connection failed". I know I need to pass the api_key since its a required parameter but I don't know how. I tried this:
request.setField("WWW-Authenticate", "###");
But I get the same status response.
Could anyone point me to the right direction please? I'm quite lost, it's the first time I try to use this libraries.
Note: I replaced my personal API key with "###"