Get HTTPS - 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: Get HTTPS (
/showthread.php?tid=639508)
Get HTTPS -
Misiur - 18.08.2017
Is it possible to fetch HTTPS resource from PAWN? HTTP returns HTTP_ERROR_BAD_HOST code.
Re: Get HTTPS -
Vince - 18.08.2017
Have you tested on other secure sites too? Because I used to get this error all the time even on non-secured sites. Don't know what causes it.
Re: Get HTTPS -
Misiur - 18.08.2017
This time it was my fault - you can't pass protocol in the url param... Now I get error 6 (malformed response) - the site doesn't offer page's http version
Re: Get HTTPS -
TheCman - 19.08.2017
Nope, it's not possible to use HTTPS with SAMP's HTTP library, and that's why you have to omit the protocol - it's assumes you're fetching a cleartext URI.
That's the kind of reasons why I use Python instead of Pawn for all my new dev, it's a much more reliable ecosystem since you don't have to depend on what the SAMP team cared to implement or not.
In that case, it could be as simple as:
Код:
import requests
APP_ID = 'b1b15e88fa797225412429c1c50c122a1'
API_URL = 'http://samples.openweathermap.org/data/2.5'
CITY = 'Paris'
def OnPlayerCommandText(playerid, cmdtext):
if cmdtext == '/weather':
response = requests.get(
'{API_URL}/weather?q={CITY}&appid={APP_ID}'.format(
**globals()
)
)
return SendClientMessage(
playerid,
0x00FFFFFF,
'The weather in {CITY} is "{description}"'.format(
description=response.json()['weather'][0]['description'],
**globals()
)
)
This is obviously untested, so don't complain if it doesn't work, it's just an example of how easy things can be.
I'll probably write a tutorial soon about how to get started with Python on SAMP.