SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Plugin Development

Reply
 
Thread Tools Display Modes
Old 29/05/2018, 10:38 PM   #31
Cadilab
Little Clucker
 
Cadilab's Avatar
 
Join Date: May 2017
Location: bl
Posts: 26
Reputation: 1
Default Re: HTTP(S) Requests+JSON Plugin - Make HTTP(S) Requests with JSON

Thanks lord for this release! I had started working on a laravel project a couple of weeks ago and this is really going be helpful, like someone already said, we can basically separate database from gamemode completely and let the backend handle all stuff. Thanks Southclaw.
__________________
Cadilab is offline   Reply With Quote
Old 29/05/2018, 11:40 PM   #32
Dignity
High-roller
 
Dignity's Avatar
 
Join Date: May 2013
Location: Belgium
Posts: 1,933
Reputation: 1102
Default Re: HTTP(S) Requests+JSON Plugin - Make HTTP(S) Requests with JSON

This is amazing. Great job!
Dignity is offline   Reply With Quote
Old 30/05/2018, 01:51 PM   #33
[HLF]Southclaw
High-roller
 
[HLF]Southclaw's Avatar
 
Join Date: Apr 2009
Location: England
Posts: 4,948
Reputation: 1510
Default Re: HTTP(S) Requests+JSON Plugin - Make HTTP(S) Requests with JSON

0.6.1 Released with some crucial bug fixes, I advise any users to update right away:

https://github.com/Southclaws/pawn-requests/releases
__________________
Tools:

Plugins:

Links:

[HLF]Southclaw is offline   Reply With Quote
Old 31/05/2018, 04:40 PM   #34
BrunoBM23
Little Clucker
 
Join Date: Mar 2018
Location: Brazil
Posts: 45
Reputation: 52
Default Re: HTTP(S) Requests+JSON Plugin - Make HTTP(S) Requests with JSON

Amazing, thanks for the release.
BrunoBM23 is offline   Reply With Quote
Old 17/06/2018, 09:13 PM   #35
pawnoholic
Big Clucker
 
Join Date: Oct 2017
Posts: 76
Reputation: 3
Default Re: HTTP(S) Requests+JSON Plugin - Make HTTP(S) Requests with JSON

Quote:
Originally Posted by [HLF]Southclaw View Post
Yes you can either pass the key as a query `?key=123` or add it as a HTTP header.
How to add a HTTP header?

PHP Code:
#define COMMUNITY_URL "http://localhost/"
#define API_KEY "839e20ff049bdea1f63b8b4e4d197e4f"
#define END_POINT "/core/hello"

new Headers:headers RequestHeaders("Authorization""Bearer " API_KEY);

client RequestsClient(COMMUNITY_URL "api"headers);

Request(clientEND_POINTHTTP_METHOD_GET"OnGetData", .headers headers); 
API Response error: INVALID_API_KEY
__________________
GitHub: @pawnoholic
pawnoholic is offline   Reply With Quote
Old 17/06/2018, 09:49 PM   #36
[HLF]Southclaw
High-roller
 
[HLF]Southclaw's Avatar
 
Join Date: Apr 2009
Location: England
Posts: 4,948
Reputation: 1510
Default Re: HTTP(S) Requests+JSON Plugin - Make HTTP(S) Requests with JSON

That's completely valid, you're adding the header correctly. However, you don't need to specify the header for each request if you've specified it for the RequestsClient already.

However I don't think that's the correct way to send the IPS/IPB authentication information, apparently you must send it as a HTTP basic auth header: https://invisioncommunity.com/4guide...-request-r167/
__________________
Tools:

Plugins:

Links:

[HLF]Southclaw is offline   Reply With Quote
Old 18/06/2018, 09:05 PM   #37
pawnoholic
Big Clucker
 
Join Date: Oct 2017
Posts: 76
Reputation: 3
Default Re: HTTP(S) Requests+JSON Plugin - Make HTTP(S) Requests with JSON

As it can be implemented on PAWN this sample code in PHP:

PHP Code:
<?php
$communityUrl 
'http://www.example.com/ips4/';
$apiKey 'c7a349a1629f02cd2855a58d77646f6d';
    
$curl curl_init$communityUrl 'api/core/hello' );
curl_setopt_array$curl, array(
    
CURLOPT_RETURNTRANSFER    => TRUE,
    
CURLOPT_HTTPAUTH    => CURLAUTH_BASIC,
    
CURLOPT_USERPWD        => "{$apiKey}:"
) );
$response curl_exec$curl );

echo 
$response;
__________________
GitHub: @pawnoholic
pawnoholic is offline   Reply With Quote
Old 18/06/2018, 10:10 PM   #38
[HLF]Southclaw
High-roller
 
[HLF]Southclaw's Avatar
 
Join Date: Apr 2009
Location: England
Posts: 4,948
Reputation: 1510
Default Re: HTTP(S) Requests+JSON Plugin - Make HTTP(S) Requests with JSON

Ah, you must use HTTP Basic Authentication. For this, you simply set one header with the format "username:password" base64 encoded.

According to the docs, you set the username to the API key and the password is empty.

So using the example "c7a349a1629f02cd2855a58d77646f6d" the string would be:

Code:
c7a349a1629f02cd2855a58d77646f6d:
Which makes the entire string into:

Code:
Basic YzdhMzQ5YTE2MjlmMDJjZDI4NTVhNThkNzc2NDZmNmQ6
Using this tool: https://www.blitter.se/utils/basic-a...der-generator/

Making the final code:

PHP Code:
#define COMMUNITY_URL "http://localhost/"
#define API_KEY "839e20ff049bdea1f63b8b4e4d197e4f"
#define END_POINT "/core/hello"

new Headers:headers RequestHeaders("Authorization""Basic YzdhMzQ5YTE2MjlmMDJjZDI4NTVhNThkNzc2NDZmNmQ6");

client RequestsClient(COMMUNITY_URL "api"headers);

Request(clientEND_POINTHTTP_METHOD_GET"OnGetData"); 
However you should not bake in your credentials like this. There are many base64 encoding implementations in Pawn so you should use that to generate the auth string at runtime.

Hope that helped!
__________________
Tools:

Plugins:

Links:


Last edited by [HLF]Southclaw; 19/06/2018 at 07:47 PM.
[HLF]Southclaw is offline   Reply With Quote
Old 19/06/2018, 07:33 PM   #39
pawnoholic
Big Clucker
 
Join Date: Oct 2017
Posts: 76
Reputation: 3
Default Re: HTTP(S) Requests+JSON Plugin - Make HTTP(S) Requests with JSON

Quote:
Originally Posted by [HLF]Southclaw View Post
Hope that helped!
Thanks! Everything works fine.
__________________
GitHub: @pawnoholic
pawnoholic is offline   Reply With Quote
Old 26/07/2018, 04:56 PM   #40
OwlIT
Little Clucker
 
Join Date: Jul 2015
Posts: 28
Reputation: 1
Default Re: HTTP(S) Requests+JSON Plugin - Make HTTP(S) Requests with JSON

Which are the advantages to declare a single request Client (during the initialization) instead of declaring a per player client? Let's suppose that I use JWT (with an infinite expires_in) to protect my APIs being accessed by everyone. What happens if someone finds the main global token?
OwlIT is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
[Plugin] SAMPSON - A JSON plugin for SA-MP KingHual Plugin Development 27 18/07/2018 03:26 PM
JSON and SAMP HTTP davidbull Scripting Help 0 05/09/2016 06:07 AM
[HELP] Vehicles.json don't load Stefand Scripting Help 1 21/02/2012 02:19 PM
HTTP() callback won't fire, + server crash using HTTP() KoczkaHUN Bug Reports 6 14/12/2011 09:35 AM
vehicles.json help plz sherlock Server Support 3 02/01/2011 12:41 PM


All times are GMT. The time now is 12:39 PM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.