HTTP Question
#5

Example code:
pawn Код:
#include <a_samp>
#include <a_http>

main () {
    HTTP(0, HTTP_GET, "bitcoin.price.exchange/update", "", "LoadedBTC");
}

forward LoadedBTC(inedx, response_code, data[]);
public LoadedBTC(inedx, response_code, data[])
{
    if (response_code == 200) {
        new
            Float:price,
            priceStr[32],
            offset
        ;
        for(new i = 0; i < cellmax; ++i) {
            offset = 9 + i;
            if (data[offset] == ',') break;

            priceStr[i] = data[offset];
        }

        price = floatstr(priceStr);

        printf("1 USD = %.2f BTC", price);
    } else {
        // Do something else when request fails
    }
}
1. The website owner may be not happy with you freeloading his data, but we can't use any free api because they all use HTTPS (as they should)
2. This assumes data structure won't change, so keep an eye if the result is mangled in the future
Reply


Messages In This Thread
HTTP Question - by BalkanEliteRP - 08.01.2018, 16:47
Re: HTTP Question - by Abagail - 08.01.2018, 17:18
Re: HTTP Question - by Misiur - 08.01.2018, 17:51
Re: HTTP Question - by BalkanEliteRP - 09.01.2018, 10:51
Re: HTTP Question - by Misiur - 09.01.2018, 11:10
Re: HTTP Question - by BalkanEliteRP - 09.01.2018, 11:56

Forum Jump:


Users browsing this thread: 1 Guest(s)