HTTP Question - 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: HTTP Question (
/showthread.php?tid=647668)
HTTP Question -
BalkanEliteRP - 08.01.2018
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!
Re: HTTP Question -
Abagail - 08.01.2018
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.
Re: HTTP Question -
Misiur - 08.01.2018
Hm, last time I checked samp HTTP API did not support HTTPS. Did that change?
Re: HTTP Question -
BalkanEliteRP - 09.01.2018
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...
Re: HTTP Question -
Misiur - 09.01.2018
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
Re: HTTP Question -
BalkanEliteRP - 09.01.2018
Hi
Thank you very much!
I'm test it,it works (
http://prntscr.com/hy0tg4 )