Ih all I'm an italian student.
In my project I want to download an image by a url. Everything is fine until I try to download an image bigger than 4KB. The problem (i think) is the max size of string.
I'll post the code. Maybe there is an error!
string DownloadHtml(string Url){
//Split the url (Why I have to do this??)
unsigned EndBase = Url.find("/",7); //Jump over the "http://" and search for another "/"
string BaseURL = Url.substr(0,EndBase);
string Page = Url.substr(EndBase);
// Create a new HTTP client
sf::Http http;
http.setHost(BaseURL);
// Prepare a request
sf::Http::Request request(Page);
// Send the request
sf::Http::Response response = http.sendRequest(request);
// Check the status code and display the result
sf::Http::Response::Status status = response.getStatus();
if (status == sf::Http::Response::Ok)
{
return response.getBody();
}
else
{
std::cout << "Error " << status << std::endl;
}
}
//Load the image from Url into sf::Texture
sf::Texture GetCopertina(string Url){
sf::Texture Txt;
string FileCopertina = DownloadHtml(Url);
long int Dim = FileCopertina.length();
Txt.loadFromMemory(FileCopertina.c_str(),Dim);
return Txt;
}
It's possible to download a file with http and sfml?