Raised This Month: $32 Target: $400
 8% 

Solved Sockets query website : GET


Post New Thread Reply   
 
Thread Tools Display Modes
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 01-08-2018 , 21:45   Re: Sockets query website : GET
Reply With Quote #11

Same, fysiks, if I go to the url and view source it looks perfect. For some reason it is doing this with sockets though.
__________________
Bugsy is offline
ish12321
Veteran Member
Join Date: May 2016
Old 01-09-2018 , 03:47   Re: Sockets query website : GET
Reply With Quote #12

Code:
/* Sublime AMXX Editor v2.2 */ #include <amxmodx> // #include <amxmisc> // #include <cstrike> // #include <engine> // #include <fakemeta> // #include <hamsandwich> // #include <fun> // #include <xs> // #include <sqlx> #include <sockets> #define PLUGIN  "TEST" #define VERSION "1.0" #define AUTHOR  "Ish Chhabra" #define PLUGIN_HOST "pluginszone.000webhostapp.com" #define PLUGIN_TOPIC "/query.php" #define TASKID_WAITANSWER 1231213 new g_Socket; new g_Data[1024]; public plugin_init() {     register_plugin(PLUGIN, VERSION, AUTHOR)         register_concmd("plugintest", "myplugintest");      // Add your code here... } public myplugintest() {     new error     g_Socket = socket_open(PLUGIN_HOST, 80, SOCKET_TCP, error);     if(g_Socket)     {         new sendbuffer[512];         format(sendbuffer, charsmax(sendbuffer), "GET %s HTTP/1.1^nHost: %s^n^n", PLUGIN_TOPIC, PLUGIN_HOST);         socket_send(g_Socket, sendbuffer, charsmax(sendbuffer));                 set_task(1.0, "task_waitanswer", TASKID_WAITANSWER, _, _, "a", 15);     }     else     {         switch(error)         {             case 1 : server_print("Error creating socket");             case 2 : server_print("Error resolving remote hostname");             case 3 : server_print("Error connecting socket");         }     } } public task_waitanswer(id) {     if(socket_change(g_Socket))     {         socket_recv(g_Socket, g_Data, charsmax(g_Data));                 server_print("%s", g_Data)             } }

This is the updated code I'm using


This is what I get
PHP Code:
HTTP/1.1 200 OK                                  
Date
Tue09 Jan 2018 08:44:14 GMT              
Content
-Typetext/htmlcharset=UTF-8           
Transfer
-Encodingchunked                       
Connection
keep-alive                           
Server
awex                                     
X
-Xss-Protection1mode=block                  
X
-Content-Type-Optionsnosniff                  
X
-Request-ID3974a9fe3b4ed6 
__________________
['O|s|G'] | Death Wins a.k.a Ish Chhabra was here
ish12321 is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 01-09-2018 , 07:53   Re: Sockets query website : GET
Reply With Quote #13

The data does exist after the http header but it is in a format that will not display in the console and AMX-X is reading it in an unexpected way. I can create a function to 'fix' the data but it would be better to find the root cause and fix it. Possibly a statement in the request header can address this but Im not sure.
__________________
Bugsy is offline
klippy
AlliedModders Donor
Join Date: May 2013
Location: Serbia
Old 01-09-2018 , 08:20   Re: Sockets query website : GET
Reply With Quote #14

PHP Code:
Header("Content-Type: text/plain"); 
"Header" should be lowercase as far as I am aware, i.e: "header".

However it seems like your web server doesn't even process PHP.

EDIT: Naaah, some things in PHP are case-sensitive and others (like function names) aren't. Stupid PHP.

Anyway I tried writing a quick PHP script for 000webhost website too and it seems like you can't use that host. It already creates some output and doesn't let me change headers from PHP because of it, but it does process my PHP anyway.
EDIT: I had an invisible whitespace character before the opening <?php tag. Thank you Sublime Text for hiding it.
I just uploaded this script to site's "public_html" directory as "query.php".
PHP Code:
<?php
// Disable cache
header("Cache-Control: no-store, no-cache, must-revalidate, max-age=0");
header("Cache-Control: post-check=0, pre-check=0"false);
header("Pragma: no-cache");

header('Content-Type: text/plain');


if(
$_SERVER['REQUEST_METHOD'] !== 'GET' || !isset($_GET['request']))
{
    exit;
}

if(
$_GET['request'] === 'current_version')
{
    echo 
'"current_version" "1.0.4b"';
}
else if(
$_GET['request'] === 'version')
{
    echo 
'"version" "1.0.0"';
}
?>
Results: http://kuckuckuc.000webhostapp.com/q...urrent_version
__________________

Last edited by klippy; 01-09-2018 at 08:49.
klippy is offline
ish12321
Veteran Member
Join Date: May 2016
Old 01-09-2018 , 10:32   Re: Sockets query website : GET
Reply With Quote #15

This is the new output...
I did added ?request=current_version to thr get string..
Code:
HTTP/1.1 200 OK                                          Date: Tue, 09 Jan 2018 15:59:32 GMT                      Server: Apache                                          Cache-Control: no-store, no-cache, must-revalidate, max- age=0, post-check=0, pre-check=0                        Pragma: no-cache                                        Transfer-Encoding: chunked                              Content-Type: text/plain;charset=UTF-8                                                                          1a                                                      "c
__________________
['O|s|G'] | Death Wins a.k.a Ish Chhabra was here

Last edited by ish12321; 01-09-2018 at 12:18.
ish12321 is offline
ish12321
Veteran Member
Join Date: May 2016
Old 01-09-2018 , 10:41   Re: Sockets query website : GET
Reply With Quote #16

Doubting host issue I opened up another free domain on another host : pluginszone.tk
__________________
['O|s|G'] | Death Wins a.k.a Ish Chhabra was here
ish12321 is offline
ish12321
Veteran Member
Join Date: May 2016
Old 01-09-2018 , 12:56   Re: Sockets query website : GET
Reply With Quote #17

Quote:
Originally Posted by Bugsy View Post
The data does exist after the http header but it is in a format that will not display in the console and AMX-X is reading it in an unexpected way. I can create a function to 'fix' the data but it would be better to find the root cause and fix it. Possibly a statement in the request header can address this but Im not sure.
If you could fix this please help :-/
__________________
['O|s|G'] | Death Wins a.k.a Ish Chhabra was here
ish12321 is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 01-09-2018 , 21:24   Re: Sockets query website : GET
Reply With Quote #18

If your PHP script is working properly, I doubt you should need to do any special processing. To me, it looks like Bugsy's comment was only valid back when your PHP script was not working properly.

What does the returned data look like with a working PHP script?
__________________
fysiks is offline
ish12321
Veteran Member
Join Date: May 2016
Old 01-10-2018 , 03:01   Re: Sockets query website : GET
Reply With Quote #19

Quote:
Originally Posted by fysiks View Post
If your PHP script is working properly, I doubt you should need to do any special processing. To me, it looks like Bugsy's comment was only valid back when your PHP script was not working properly.

What does the returned data look like with a working PHP script?
In https://www.hurl.it I get proper body but not in amxmodx sockets
__________________
['O|s|G'] | Death Wins a.k.a Ish Chhabra was here
ish12321 is offline
ish12321
Veteran Member
Join Date: May 2016
Old 01-10-2018 , 07:08   Re: Sockets query website : GET
Reply With Quote #20

Hey, just now instead of server_print I used log_amx and in log files I find the data to be present.. Just it doesnt appear in console.. Any idea why?
__________________
['O|s|G'] | Death Wins a.k.a Ish Chhabra was here
ish12321 is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 16:51.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode