Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

AppGameKit Classic Chat / agk:bete11: simple Http send problem

Author
Message
miki
19
Years of Service
User Offline
Joined: 7th Jan 2005
Location:
Posted: 8th May 2013 13:23
Hi,

Why can't I send a file to my server?





Any help please?

Thanks,
miki

in the end
Markus
Valued Member
20
Years of Service
User Offline
Joined: 10th Apr 2004
Location: Germany
Posted: 8th May 2013 13:42 Edited at: 8th May 2013 13:45
you need a receive website for this (.php).
this webseite get the post value(the file)
and then the webside can do anything with it.

getfile.php is your own script
sending = SendHTTPFile(id, "getfile.php", "" , "test1.txt")

http is not ftp
miki
19
Years of Service
User Offline
Joined: 7th Jan 2005
Location:
Posted: 8th May 2013 22:58 Edited at: 8th May 2013 23:43
How do I pass two variables to my script ...("post.php")?


why doesn't something like this work?

sending = SendHTTPRequestASync(id , "post.php" , "name=peter&score=34")


the post.php looks like this


<?php
/** Read in a username and score and save them to a file. */
// read variables from POST data.
$username = $HTTP_GET_VARS[name];
$score = $HTTP_GET_VARS[score];

// verify the username is set and not empty
if (!isset($username) || $username == "") {
echo "failure1";
exit;
}

// verify the score is set and a number
if (!isset($score) || !is_numeric($score)) {
echo "failure2";
exit;
}

// format the username and score as a comma delimited row
$entry = $username . "," . $score . "\n";

// append entry to the score file
if (!file_put_contents("scores.csv", $entry, FILE_APPEND)) {
echo "failure3"; // failed to write to file
exit;
}

echo "successyeah";
?>

in the end
Ancient Lady
Valued Member
20
Years of Service
User Offline
Joined: 17th Mar 2004
Location: Anchorage, Alaska, USA
Posted: 8th May 2013 23:41 Edited at: 8th May 2013 23:43
The third parameter (szPostData) is for passing information. It is done in the form of 'varname=varvalue'. If you have more than one variable, 'var1name=var1val&var2name=var2val'. This is discussed in the help page for SendHTTPFile.

The variable name may consist of a-z, numbers and underscore (to be safe) and must start with a letter or underscore.

The variable data may not contain spaces or characters other than a-z, 0-9, underscore (_), percent (%). Actually, it can include others, but it is safest to replace them with the appropriate escaping using the percent character and the hex representation of the ascii value. A space is represented by '%20' (percent,two,zero) without the quotes. A dash is '%2D', backslash is '%2F', etc. (find a good ASCII character set chart with the decimal and hex values).

On the server side, inside your post.php file, you will extract the values from $_REQUEST['varname'] (in this case, you do use the quotes). Something like this:


I don't know if the AppGameKit stuff is using the standard file transfer protocols, but assuming it does, it will show up in the $_FILES array. This array requires a name for the index and the AppGameKit help doesn't specify what it is. Can someone at TGC please help with this information?

Assuming, just for the sake of creating an example, that the name to use is the same as set in the szLocalFile parameter.

Lets assume you make a call like this:


This is what the PHP processing within your post.php might look like (a more complete example than the one above and should be functional, assuming the passed directory exists and is writable):


Cheers,
Ancient Lady
AGK Community Tester and AppGameKit Master
Markus
Valued Member
20
Years of Service
User Offline
Joined: 10th Apr 2004
Location: Germany
Posted: 9th May 2013 00:28
what Ancient Lady means with the % char is named as url encode/decode, php have functions for this.
its used because some chars are reserved like the & char as parameter delimiter.

http://www.php.net/manual/en/function.urlencode.php

there are two kinds of transfer,
one named as GET is a single row (URL) with parameters.
POST is more for binary data, images or files, input forms.
php have functions for get & post to get his values.

also important to know are some rfc rules.
http://en.wikipedia.org/wiki/Request_for_Comments
miki
19
Years of Service
User Offline
Joined: 7th Jan 2005
Location:
Posted: 9th May 2013 00:39
@ Ancient Lady

I changed this...
// read variables from POST data.
$username = $HTTP_GET_VARS[name];
$score = $HTTP_GET_VARS[score];

to this...
// read variables from POST data.
$username = $_REQUEST[name];
$score = $_REQUEST[score];

and it worked.

Many Thanks.

in the end
Ancient Lady
Valued Member
20
Years of Service
User Offline
Joined: 17th Mar 2004
Location: Anchorage, Alaska, USA
Posted: 9th May 2013 04:33
Markus, the encoding needs to be done on parameters before the string is sent using the AppGameKit command. It is not an issue about encoding once in PHP since the encoding resolves itself automagically by the time the PHP script starts to process the inputs.

miki, I assume that your reference is meant to be from some other code, not the code I posted. I did specify using the $_REQUEST array. I would also recommend putting quotes (single quotes are fine) around the array indices. PHP will accept it the way you did it, but it is better programming practices and safer to always quote strings used for indices. I'm glad you got something to work.

Cheers,
Ancient Lady
AGK Community Tester and AppGameKit Master

Login to post a reply

Server time is: 2024-05-06 17:05:52
Your offset time is: 2024-05-06 17:05:52