Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Download text-file  (Read 32984 times)

0 Members and 2 Guests are viewing this topic.

dabo

  • Sr. Member
  • ****
  • Posts: 260
    • View Profile
    • http://www.dabostudios.net
Download text-file
« Reply #15 on: August 03, 2008, 09:18:42 pm »
Quote from: "Daazku"
Quote from: "dabo"
I have finally solved it :D. This is the solution:

Instead of using this request:
Code: [Select]
const char request[] = "GET /text.txt HTTP/1.1\r\n"
"\r\n";

I used this:
Code: [Select]
const char request[] = "GET /text.txt HTTP/1.1\r\n"
"Host: www.dabostudios.net\r\n"
"\r\n";

I dont know why that host row made the difference I'm just happy it works.


You always need to specify host name because for a same ip you can have 4395 sites on that ip so the server need to know wich one you want to see.

Exemple: SFML is on the IP 213.186.33.2 but if you past-it in your browser you will see the ovh webmail page. If you add the host field in your http header request with the name sfml-dev.org you will see sfml. (Firefox have alot of add-on to do that like tamper-data ou Modify headers or Http Lives Headers etc etc...


I see, thanks.

WorldRacer

  • Newbie
  • *
  • Posts: 16
    • View Profile
Download text-file
« Reply #16 on: May 27, 2009, 10:27:41 pm »
Can anybody post the whole working code, because I'm too lazy now  to tinker the code snippets xD

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Download text-file
« Reply #17 on: May 27, 2009, 10:29:27 pm »
SFML now has a sf::Http class ;)
Laurent Gomila - SFML developer

WorldRacer

  • Newbie
  • *
  • Posts: 16
    • View Profile
Download text-file
« Reply #18 on: May 27, 2009, 10:47:18 pm »
VERY BIG THANK, GUY!!!

Soluted the Problem this way:

Code: [Select]

// Init HTTP Client
sf::Http Http;

// Set the Host
Http.SetHost("www.yourdomain.tld");

// Get the file
sf::Http::Response Response = Http.SendRequest(sf::Http::Request::Request(sf::Http::Request::Method::Get, "http://www.yourdomain.tld/dir/foo/bar.ext"));

// Save the downloaded text into a string
std::string Body = Response.GetBody();

// Save the file
FILE *fTextFile;
fTextFile = fopen("bar.ext", "w" );
fputs(Body.c_str(), fTextFile);
fclose(fTextFile);


^^Now the file is saved as bar.ext into the working directory of the project.