HTTP Question
#1

Hi

I'm don't have experience with HTTP so i have an question.If you can tell me is this possible to do(and how,if you know)

Is possible that i "get" BitCoin price from this site,for example:
https://charts.bitcoin.com/chart/price

And i want to show BitCoin price on my server.You can see BitCoin price here: http://prntscr.com/hxocke

Or it's only possible to load .txt files?

Thank you!
Reply
#2

You can make use of the HTTP function in a_http (#include a_http). This will work better on actual APIs than the page you linked, as it will be difficult to read off what is returned and make use of it.

For example, this will return data in a formatted json string, which is more usable. More information on the HTTP function here.
Reply
#3

Hm, last time I checked samp HTTP API did not support HTTPS. Did that change?
Reply
#4

Quote:
Originally Posted by Misiur
Посмотреть сообщение
Hm, last time I checked samp HTTP API did not support HTTPS. Did that change?
It's really don't important if i can't from this page.Maybe can from this:

http://www.kitco.com/bitcoin-price-charts-usd/
or this
http://bitcoin.price.exchange/

But i still don't know how to get price from website...
Reply
#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
#6

Hi

Thank you very much!
I'm test it,it works ( http://prntscr.com/hy0tg4 )
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)