Get HTTPS
#1

Is it possible to fetch HTTPS resource from PAWN? HTTP returns HTTP_ERROR_BAD_HOST code.
Reply
#2

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.
Reply
#3

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
Reply
#4

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.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)