Read from website?
#1

Hello, is it possible to make the script detect the text on a website, and if it's On it'll continue the code in the script. If not it'll return false..?

Код HTML:
forward MyHttpResponse(index, response_code, data[]);
 
public OnPlayerCommandText(playerid, cmdtext[])
{
    if(!strcmp("/hello",cmdtext,true))
    {
        HTTP(playerid, HTTP_GET, "kc.gd/hello.txt", "", "MyHttpResponse");
        return 1;
    }
    return 0;
}
 
public MyHttpResponse(index, response_code, data[])
{
    // In this callback "index" would normally be called "playerid" ( if you didn't get it already :) )
    new
        buffer[ 128 ];
    if(response_code == 200) //Did the request succeed?
    {
        //Yes!
        format(buffer, sizeof(buffer), "The URL replied: %s", data);
        SendClientMessage(index, 0xFFFFFFFF, buffer);
    }
    else
    {
        //No!
        format(buffer, sizeof(buffer), "The request failed! The response code was: %d", response_code);
        SendClientMessage(index, 0xFFFFFFFF, buffer);
    }
}
Reply
#2

It can't be done within one function because HTTP requests are async. Continue execution inside callback function.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)