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.

Windows / [SOLVED] HttpResponse from PHP script help needed...

Author
Message
Conjured Entertainment
AGK Developer
19
Years of Service
User Offline
Joined: 12th Sep 2005
Location: Nirvana
Posted: 1st Aug 2020 15:38 Edited at: 1st Aug 2020 20:35
This post has been marked by the post author as the answer.
Greetings fellow AppGameKit users,

I am having trouble getting a response from the server,

Using the same PHP code that Kevin Cross shows in his like thread.

HttpResponse::setCache(true);
HttpResponse::setContentType('text/plain');
HttpResponse::setData("wtf");
HttpResponse::send();

I am finally getting a response, but it is a null value.

Is there something else that needs to be done?

Any help would be greatly appreciated.



EDIT

Has anyone else tried using the example code in the documentation for this lately ??

I get unexpected results, and it is difficult fully understanding without seeing what is on the server's end. (unless it is just a web page we are supposed to retrieve instead of displaying)

Seems all of these are pages not found at that.

So, I tried a valid webpage that does exist, and saved that response$ as a file to examine more than just the first screen, and did find that the full web page is being returned. (the text for html display and not the hidden content such as the PHP script of course)

Still unconvinced that this is the intention, but I think I may be able to work around my problem now, so it is all good.

Will try saving the information as a plain text file on the server without any frills, and I just might get the response I am looking for when calling that file directly instead of having the server send it back via the PHP script.

That would actually be better than I was expecting, so maybe I was just confused about how to use this command.

Thanks anyway, and sorry for the minutes you spent reading this that you can ever get back. lol (wasting time was not intentional)

If anyone has anything to add on the subject though, please do....


Coding things my way since 1981 -- Currently using AppGameKit V2 Tier 1

The author of this post has marked a post as an answer.

Go to answer

Conjured Entertainment
AGK Developer
19
Years of Service
User Offline
Joined: 12th Sep 2005
Location: Nirvana
Posted: 1st Aug 2020 22:01 Edited at: 1st Aug 2020 22:35
Bumping to let you know this is solved with the suggested work around. (it was already at the top, just wanted to reset as unread)

The functionality of this command is perfect, so I hope it stays as it is in future updates.

Tested a plain text file with no headers just a single string with a single line, then used the Mid() to get my data, and worked like a charm to strip the unwanted carriage return.

My plan was to condense the encrypted variables for single line entries in flat file databases anyway, so this is perfect for that.

This works great for HTML5 builds, and should work fine on shared servers since it doesn't require any scripts (PHP) to return. (just to write the file on server)

I have only tested locally with XAMPP, but it is working fine so far.

Of course I have to make two HTTP calls, one to send my data and have the script process and write results on server, and a second to return results form that file.

I may even just use the OpenBrowser() command to send the data (keyed) using GET like I did for my '6 Marbles' leaderboard, so only one HTTP call actually.

No wonder the original problem was a null value, since my PHP was all PHP and thus all of it was being hidden. lol Brainfart! Sorry

Coding things my way since 1981 -- Currently using AppGameKit V2 Tier 1
PartTimeCoder
AGK Tool Maker
9
Years of Service
User Offline
Joined: 9th Mar 2015
Location: London UK
Posted: 8th Aug 2020 22:55 Edited at: 8th Aug 2020 22:57
Quote: "If anyone has anything to add on the subject though, please do...."

Quote: "Of course I have to make two HTTP calls, one to send my data and have the script process and write results on server, and a second to return results form that file."

Quote: "No wonder the original problem was a null value, since my PHP was all PHP and thus all of it was being hidden. lol Brainfart! Sorry"


did you "echo" from your script?

a remote script need only contain PHP you can process any serverside stuff, database and what-have-you and "echo" it as a return, AppGameKit will/should retrieve this "echoed" data from SendHTTPRequest() in its return value.

there should be no need to double send anything, you send data to the script, it gets processed and the script returns data directly to AGK

Its getting late and I'v had a few beers but this has been asked a few times in the last week or so, so I'll knock up an example tomorrow If I remember/find the time/don't hit the nectar to early, PHP is built for communicating with remote clients and thats all AppGameKit is, a remote client.

Unless I am misunderstanding what your trying to do?
PartTimeCoder
AGK Tool Maker
9
Years of Service
User Offline
Joined: 9th Mar 2015
Location: London UK
Posted: 8th Aug 2020 23:05 Edited at: 8th Aug 2020 23:06
Its this simple
PHP (test.php)


AGK
Conjured Entertainment
AGK Developer
19
Years of Service
User Offline
Joined: 12th Sep 2005
Location: Nirvana
Posted: 9th Aug 2020 01:18 Edited at: 9th Aug 2020 01:25
Yeah , I have tried echoing the response back with varying results, all of which had extra data appended to what was being echoed. (special characters mixed with junk letters)

Thanks for the example.

I use a while statement to wait for the response though.

The main difference is that I use "localhost" and path names instead of the IP address. (like the example in the documentation)

I am just using text files for retrieving the data, and let the script create it.

Calling it twice like that is not elegant, but I am getting good results and it actually nice to have separate files for what I am working on.

Thanks for the help though, and I will keep trying to get it to act right, because it probably has something to do with server configuration.

I know the SendHTTPRequest does not work for HTML5 builds though (per documentation), so I am using SendHTTPRequestASync instead, hence my waiting for the GetHTTPResponseReady with the while. (just like the example in the docs for SetHTTPHost() )

I am now suspecting the HTML build differences are what is causing my problem, but the work around is doing the trick.

I got rid of the following completely, because my scripts would not work at all until I did...

HttpResponse::setCache(true);
HttpResponse::setContentType('text/plain');
HttpResponse::setData("some data");
HttpResponse::send();

Again, running the example in the documentation is sending back the entire page contents (less hidden PHP) which is actually perfect for me needs, so all is good.

Coding things my way since 1981 -- Currently using AppGameKit V2 Tier 1

Login to post a reply

Server time is: 2024-11-21 09:48:59
Your offset time is: 2024-11-21 09:48:59