Hi,
If I am understanding this correctly, the help file for SendHTTPRequestASync refers to a PHP file named app_dummy_if.php
Using the instructions:
It looks like he is getting the variables from a static PHP file
So in using the instructions it is necessary for the PHP file to hold the info...
I think the php file will be something basic holding variables?
Could someone show me what the app_dummy_if.php looks like please...
Here is the Help Code:
http = CreateHTTPConnection()
SetHTTPHost( http, "www.thegamecreators.com", 0 )
SendHTTPRequestASync( http, "agktest/posttest.php", "myvar=5" )
while GetHTTPResponseReady(http) = 0
Print( "Connecting..." )
Sync()
endwhile
response$ = GetHTTPResponse(http)
CloseHTTPConnection(http)
DeleteHTTPConnection(http)
// main loop
do
Print( "Server response: " + response$ )
Sync()
loop
// The PHP server code accesses the "myvar" value like this
// $value = (int) $_POST['myvar'];
Example by James C (AGK version: 108.24)
Submitted: 2014-09-08 13:10:21
Note: This command is not truly A-Synchronous, in the sense that multiple requests can be send and received A-Synchronously. Rather, it is a single threaded implementation of the regular SendHTTPRequest, which allows you to continue the Sync() loop to update your animations and other screen related functions, while waiting for an answer to arrive. Upon arrival that answer should be processed with GetHTTPResponse, before a new request can be send. Another important detail is that GetHTTPResponseReady will keep on returning true (1), until a new request has been sent.
Attached is an example that will show how this works:
rem
rem AGK Application
rem
#constant NO 0
#constant YES 1
http = CreateHTTPConnection()
SetHTTPHost( http, "your_web_site", 0 )
// The server will just reply with the string that was sendtto it
dim request[4] as string = ["C", "Q", "b", "A"]
dim response[4] as string = ["", "", "", ""]
dim txn[4, 2] as float // 4 requests and 4 responses
for i = 0 to 3
for j = 0 to 1
txn[i, j] = 0.0
next j
next i
jumptab = 0
// the way I use these variables is:
// if they are equal, I can send a new request, since I received an answer
// if unequal, I'm waiting for an answer. (Fail is an answer too)
send_counter = 0
response_counter = 0
do
print( str(jumptab) )
for t = 0 to 3
Print( "Sent request " + str(t) + " with data <" + request[t] + "> at timer: " + str(txn[t, 0]) )
Print( "Recv request " + str(t) + " with data <" + response[t] + "> at timer: " + str(txn[t, 1]) )
next t
tim# = timer()
if send_counter = response_counter
SendHTTPRequestASync( http, "app_dummy_if.php", "action=" + request[send_counter] )
txn[send_counter, 0] = tim#
inc send_counter
endif
my_status = GetHTTPResponseReady(http)
if my_status <> 0 AND response_counter < 4 // 0 means, still going
if my_status = -1 // -1 means failed
response[ response_counter ] = "failed"
inc response_counter
else // 1 means success, so find what we got back from server
response[ response_counter ] = GetHTTPResponse(http)
endif
txn[ response_counter , 1 ] = tim#
inc response_counter
endif
if getrawkeypressed(27) = YES then end
Sync()
inc jumptab
loop