SA-MP Forums Archive
Need a little help with a_http - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Need a little help with a_http (/showthread.php?tid=481139)



Need a little help with a_http - zT KiNgKoNg - 14.12.2013

Hey guys just trying out the HTTP functions within the a_http include to check some information in a mysql database but for some reason it keeps returning an error code (6) wich doesn't exist as far as i know.

Note: i'm trying to get it to check the information via localhost.
pawn Код:
#include <a_samp>
#include <a_mysql>
#include <a_http>
#include <sscanf2>
#include <zcmd>

#define GAMEMODE_TEST ""

#define MYSQL_HOST ""
#define MYSQL_USER ""
#define MYSQL_DATA ""
#define MYSQL_PASS ""

#define URL_CHECK_WALLET "localhost/http_walletcheck.php"


//***************************************************************************************************

forward HttpResponse_WalletCheck(index, response_code, data[]);

//***************************************************************************************************

main()
{

}

public OnGameModeInit()
{
    print("test");
}

public HttpResponse_WalletCheck(index, response_code, data[])
{
    new playerid = index;
    if(response_code == 200)
    {
        if(strcmp(data,"true",true) == 0)
        {
            SendClientMessage(playerid, -1, "we completed your transaction...");
        } else {
            SendClientMessage(playerid, -1, "we could not complete your transaction, please try again.");
        }

    } else {

        new str[1048];
        format(str,sizeof(str), "An error occured when processing your transaction. (RESPONSE: %d)", response_code);
        SendClientMessage(playerid, -1, str);
    }
}

COMMAND:checkwallet(playerid, params[])
{
    new str[500];
    format(str,sizeof(str),"userid=%dwalletbalance=%d",1,1);
    HTTP(playerid, HTTP_POST, URL_CHECK_WALLET, str, "HttpResponse_WalletCheck");
    return 1;
}



Re: Need a little help with a_http - zT KiNgKoNg - 15.12.2013

Bump - Still in need of help.


Re: Need a little help with a_http - zT KiNgKoNg - 16.12.2013

Still in need of help with this problem...


Re: Need a little help with a_http - zT KiNgKoNg - 17.12.2013

Still need help with this problem, if anyone is going to bother helping me.


Re: Need a little help with a_http - zT KiNgKoNg - 18.12.2013

Is anyone able to help me on this problem?


Re: Need a little help with a_http - CutX - 18.12.2013

Quote:
Originally Posted by zT KiNgKoNg
Посмотреть сообщение
it keeps returning an error code (6) wich doesn't exist as far as i know.
Return code 6 exists.

You're gettin' a malformed response.

Just guessin' this but maybe Something's not right in your php file or youre sending wrong data.

(https://sampwiki.blast.hk/wiki/HTTP)


AW: Need a little help with a_http - BigETI - 18.12.2013

If you want to send a GET request, leave the POST request string blank.

Example GET request with URL:
Код:
subdomain.example.domain/example_folder/example_file.php?variable1=string1&variable2=string2



Re: Need a little help with a_http - zT KiNgKoNg - 18.12.2013

Thanks for your post but i forgot to update on the bump.
now it is returning 404 (No found)

pawn Код:
#include <a_samp>
#include <a_mysql>
#include <a_http>
#include <sscanf2>
#include <zcmd>

#define GAMEMODE_TEST ""

#define MYSQL_HOST ""
#define MYSQL_USER ""
#define MYSQL_DATA ""
#define MYSQL_PASS ""


//***************************************************************************************************

forward HttpResponse_WalletCheck(index, response_code, data[]);

//***************************************************************************************************

main()
{

}

public OnGameModeInit()
{
    print("test");
}

public HttpResponse_WalletCheck(index, response_code, data[])
{
    new playerid = index;
    if(response_code == 200)
    {
        if(strcmp(data,"true",true) == 0)
        {
            SendClientMessage(playerid, -1, "we completed your transaction...");
        } else {
            SendClientMessage(playerid, -1, "we could not complete your transaction, please try again.");
        }

    } else {

        new str[1048];
        format(str,sizeof(str), "An error occured when processing your transaction. (RESPONSE: %s)", ResponseCodeString(response_code));
        SendClientMessage(playerid, -1, str);
    }
}

COMMAND:checkwallet(playerid, params[])
{
    new str[500];
    format(str,sizeof(str),"ID=%i&Wallet=%i",1,1);

    HTTP(playerid, HTTP_POST, "127.0.0.1/http/http_walletcheck.php", str, "HttpResponse_WalletCheck");
    return 1;
}

stock strreplace(string[], find, replace)
{
    for(new i=0; string[i]; i++)
    {
        if(string[i] == find)
        {
            string[i] = replace;
        }
    }
    return true;
}


stock ResponseCodeString(code)
{
    new rtstring[175];
    switch(code)
    {
        case 100: { rtstring = "Continue"; }
        case 101: { rtstring = "Switching Protocols"; }
        case 102: { rtstring = "Processing"; }
        case 200: { rtstring = "Successful"; }
        case 201: { rtstring = "Created"; }
        case 202: { rtstring = "Accepted"; }
        case 203: { rtstring = "Non-Authoritative Information"; }
        case 204: { rtstring = "No Conten"; }
        case 205: { rtstring = "Reset Content"; }
        case 206: { rtstring = "Partial Content"; }
        case 207: { rtstring = "Multi-Status"; }
        case 208: { rtstring = "Already Reported"; }
        case 226: { rtstring = "IM Used"; }
        case 300: { rtstring = "Multiple Choices"; }
        case 301: { rtstring = "Moved Permanently"; }
        case 302: { rtstring = "Found"; }
        case 303: { rtstring = "See Other"; }
        case 304: { rtstring = "Not Modified"; }
        case 305: { rtstring = "Use Proxy"; }
        case 306: { rtstring = "Switch Proxy"; }
        case 307: { rtstring = "Temporary Redirect"; }
        case 308: { rtstring = "Permanent Redirect"; }
        case 400: { rtstring = "Bad Request"; }
        case 401: { rtstring = "Unauthorized"; }
        case 402: { rtstring = "Payment Required"; }
        case 403: { rtstring = "Forbidden"; }
        case 404: { rtstring = "Not Found"; }
        case 405: { rtstring = "Method Not Allowed"; }
        case 406: { rtstring = "Not Acceptable"; }
        case 407: { rtstring = "Proxy Authentication Required"; }
        default: { rtstring = "Unkown Code Response"; }
    }
    return rtstring;
}



Re: Need a little help with a_http - zT KiNgKoNg - 19.12.2013

Help still needed.


Re: Need a little help with a_http - Kells - 19.12.2013

whats the problem exactly