[b]Problem Solved[/b]
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]
#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);
}
[/code]
GetRequest.php
[code]
<?php
$name = $_POST["firstname"];
$lastname = $_POST["last"];
$list = fopen("savename.txt", 'a');
fwrite($list, $name);
fwrite($list, " ");
fwrite($list, $lastname);
fwrite($list, "\n");
fclose($list);
?>
[/code]
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?
Also, sorry if this should be in the Web Development forum.
I'm not sure what the problem might be, but I'd try doing a print_r($_POST) in PHP and see what it gives, and also I'd write a response and try to read it frm your C++ app.
[QUOTE=Xeon06;25726459]I'm not sure what the problem might be, but I'd try doing a print_r($_POST) in PHP and see what it gives, and also I'd write a response and try to read it frm your C++ app.[/QUOTE]
I wrote in the file $_POST but all I got was "Array".
[url]http://sfml-dev.org/documentation/1.6/classsf_1_1Http_1_1Request.htm#8f8b740b23e13d757e8dabd634eb8e46[/url]
[quote]Parameters:
Body : Content of the request body
This parameter is optional and makes sense only for POST requests. This parameter is empty by default [/quote]
To me this seems to mean that you should be doing this:
[code]
req.SetBody("\
<form>\n\
<input type="text" name="firstname" />\n\
<input type="text" name="last" /> \n\
</form> \n\
");
[/code]
Combined with these lines I believe it will work.
req.SetField("firstname", "aus");
req.SetField("last", "tech");
ATM you are telling it to set post variables which don't exist.
BTW call SetBody before the SetField calls.
Never used this but that's what I think.
I've never used this aus, but try this:
[cpp]
sf::Http http;
sf::Http::Request req;
req.SetMethod(sf::Http::Request::Post);
req.SetUri("/GetRequest.php");
req.setBody( "firstname=aus&last=tech" );
http.SetHost("http://theaustech.110mb.com");
http.SendRequest(req);[/cpp]
[editline]30th October 2010[/editline]
[QUOTE=Jallen;25727010][url]http://sfml-dev.org/documentation/1.6/classsf_1_1Http_1_1Request.htm#8f8b740b23e13d757e8dabd634eb8e46[/url]
To me this seems to mean that you should be doing this:
[code]
req.SetBody("\
<form>\n\
<input type="text" name="firstname" />\n\
<input type="text" name="last" /> \n\
</form> \n\
");
[/code]
Combined with these lines I believe it will work.
req.SetField("firstname", "aus");
req.SetField("last", "tech");
ATM you are telling it to set post variables which don't exist.
BTW call SetBody before the SetField calls.
Never used this but that's what I think.[/QUOTE]
Pretty sure the POST content body has nothing to do with the form, and is just the get variables as a string on its own like in my post.
[QUOTE=r4nk_;25727104]I've never used this aus, but try this:
[cpp]
sf::Http http;
sf::Http::Request req;
req.SetMethod(sf::Http::Request::Post);
req.SetUri("/GetRequest.php");
req.setBody( "firstame=aus&last=tech" );
http.SetHost("http://theaustech.110mb.com");
http.SendRequest(req);[/cpp]
[editline]30th October 2010[/editline][/QUOTE]
fool its on, you rate me disagree and i rate you disagree, its a showdown now
austech you have to post the winner to settle this feud of great magnitude
r8 dumb m8
Seriously though, this is just going from how it's done with a POST ajax request...
fuck r4nk_ was right
whatever man im out of here
Rank was right. :v:
[QUOTE=xAustechx;25727318]Rank was right. :v:[/QUOTE]
right*
ninjad
whatever man im out of here again
Also sorry for the poor punctuation and troll like appearance of my posts, its the frustration of using a netbook keyboard, it activates my inner troll.
Yeah I didn't see that coming :smug:
But I don't understand why sfml wouldn't automatically set it for you if it already has functions that let you set the field names and values for GET...
[QUOTE=Jallen;25727327]right*
ninjad
whatever man im out of here again[/QUOTE]
Gonna eat that chocolate?
[QUOTE=r4nk_;25727336]Yeah I didn't see that coming :smug:
But I don't understand why sfml wouldn't automatically set it for you if it already has functions that let you set the field names and values for GET...[/QUOTE]
Yeah that's pretty wierd.
Austech, could you try removing the SetField calls for curiosity's sake?
[editline]29th October 2010[/editline]
[QUOTE=xAustechx;25727338]Gonna eat that chocolate?[/QUOTE]
:frown:
[QUOTE=Jallen;25727376]Yeah that's pretty wierd.
Austech, could you try removing the SetField calls for curiosity's sake?
[editline]29th October 2010[/editline]
:frown:[/QUOTE]
My code is without the set fields and should work..
Oh right I just skimmed over it and saw your different SetBody call.
Well yeah that definitely is wierd. That could be seen as a bug. Or at least if it does what it's intended to then it should be better documented.
I guess it's so you can send GET and POST variables with one request
[editline]30th October 2010[/editline]
Wait but you tell SFML what request type it is :S so that can't be right
Sorry, you need to Log In to post a reply to this thread.