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

Author Topic: Sending a Request Problem  (Read 2672 times)

0 Members and 1 Guest are viewing this topic.

Austech

  • Newbie
  • *
  • Posts: 23
    • View Profile
Sending a Request Problem
« on: October 29, 2010, 08:53:57 pm »
I'm trying to send a POST request to my site, then the site saves that info in a file. The problem is that it apparently isn't receiving the fields I set.


C++ Program:

Code: [Select]

#include <iostream>
#include <string>
#include <SFML/Network.hpp>

int main()
{
sf::Http http;
sf::Http::Request req;

req.SetMethod(sf::Http::Request::Post);

req.SetUri("/GetRequest.php");

req.SetField("firstname", "aus");
req.SetField("last", "tech");

http.SetHost("http://theaustech.110mb.com");

http.SendRequest(req);
}


GetRequest.php
Code: [Select]

<?php

$name 
$_POST["firstname"&#93;;
$lastname $_POST["last"&#93;;

$list fopen&#40;"savename.txt", 'a'&#41;;
fwrite&#40;$list, $name&#41;;
fwrite&#40;$list, " "&#41;;
fwrite&#40;$list, $lastname&#41;;
fwrite&#40;$list, "\n"&#41;;
fclose&#40;$list&#41;;
?>





The request is getting sent though, because every time I run this program, I check the savename.txt file and there's a new line added. So that means that the name nor the lastname field is being grabbed since it's outputting nothing but the new line.

Does anyone know what I did wrong? Or how I can go about fixing it?

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Sending a Request Problem
« Reply #1 on: October 29, 2010, 09:10:55 pm »
With POST, variables must be encoded in the body of the message, not in the header fields.

Code: [Select]
req.SetBody("firstname=aus&las=tech");
Laurent Gomila - SFML developer