09.01.2018, 11:10
Example code:
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
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
}
}
2. This assumes data structure won't change, so keep an eye if the result is mangled in the future