Raised This Month: $248 Target: $400
 62% 

REST in Pawn 1.2 - HTTP client for JSON REST APIs (Updated 2020/09/13)


Post New Thread Reply   
 
Thread Tools Display Modes
splinterz
Junior Member
Join Date: Sep 2011
Old 05-29-2020 , 04:45   Re: REST in Pawn - Communicate with JSON REST APIs
Reply With Quote #71

Quote:
Originally Posted by Matix8981 View Post
I created simple debugging script in PHP for check if rest in pawn sending POST data to target HTTP but can't see any POST data in apache logs i see request from my csgo server.

Debugging script:
PHP Code:
<?php
    file_put_contents
("file.json"json_encode([$_REQUEST$_GET$_POST]));
?>
Output JSON file:
Code:
[[],[],[]]
Plugin:
PHP Code:
void RequestChecker()
{
    
HTTPClient client = new HTTPClient("PAGE");
    
JSONObject post = new JSONObject();
    
post.SetString("type""csgo");
    
post.SetString("param1""string_first");
    
post.SetString("param2""string_second");
    
    
client.Post("index.php"postRequestCheckerCallback);
    
    
delete post;
}

void RequestCheckerCallback(HTTPResponse responseany value)
{
    if (
response.Status != HTTPStatus_Created)
    {
        
PrintToServer("Error 01");
        return;
    }
    if (
response.Data == null)
    {
        
PrintToServer("Error 02");
        return;
    }
    
    
JSONObject post view_as<JSONObject>(response.Data);
    
char param1[128];
    
post.GetString("param1"param1sizeof(param1));
    
    
PrintToServer("Param one %d"param1);

hi, did u fix this?
i got same error like this..
i got null response.Data and i got empty json on my web server..
i tried to use api tester and its working fine so it should be my sourcemod plugin
splinterz is offline
Peace-Maker
SourceMod Plugin Approver
Join Date: Aug 2008
Location: Germany
Old 06-02-2020 , 06:42   Re: REST in Pawn - Communicate with JSON REST APIs
Reply With Quote #72

Quote:
Originally Posted by splinterz View Post
hi, did u fix this?
i got same error like this..
i got null response.Data and i got empty json on my web server..
i tried to use api tester and its working fine so it should be my sourcemod plugin
You'll have to check the request body in PHP instead of the request parameters. Check this.

The request Content-Type is application/json instead of application/x-www-form-urlencoded.

PHP Code:
$body file_get_contents('php://input');
$data json_decode($body); 
__________________
Peace-Maker is offline
DJ Tsunami
DJ Post Spammer
Join Date: Feb 2008
Old 06-21-2020 , 14:45   Re: REST in Pawn 1.2 - HTTP client for JSON REST APIs (Updated 2020/06/21)
Reply With Quote #73

New release:
  • Added ability to download and upload files
  • Added ability to iterate over keys in a JSON object
  • Optimized performance (thanks Gunslinger)
Download
__________________
DJ Tsunami is online now
mrtn
Junior Member
Join Date: May 2020
Old 07-10-2020 , 17:14   Re: REST in Pawn 1.2 - HTTP client for JSON REST APIs (Updated 2020/06/21)
Reply With Quote #74

Quote:
Originally Posted by DJ Tsunami View Post
New release:
  • Added ability to iterate over keys in a JSON object
Key iteration works perfectly, thanks!
mrtn is offline
DJ Tsunami
DJ Post Spammer
Join Date: Feb 2008
Old 07-17-2020 , 04:00   Re: REST in Pawn 1.2 - HTTP client for JSON REST APIs (Updated 2020/06/21)
Reply With Quote #75

Version 1.2.0 did not properly clean up requests, please update to version 1.2.1.

1.2.1 also adds support for 64-bit integers in JSON, thanks to Gunslinger.
__________________
DJ Tsunami is online now
foon
Member
Join Date: Dec 2018
Old 07-22-2020 , 10:39   Re: REST in Pawn 1.2 - HTTP client for JSON REST APIs (Updated 2020/07/16)
Reply With Quote #76

After uploading a file, should we close the handle or is that done automatically?

Code:
void OnImageUploaded(HTTPStatus status, any value)
{
    delete httpClient;
}
foon is offline
DJ Tsunami
DJ Post Spammer
Join Date: Feb 2008
Old 07-22-2020 , 12:36   Re: REST in Pawn 1.2 - HTTP client for JSON REST APIs (Updated 2020/07/16)
Reply With Quote #77

No, if your HTTP client is defined globally, there's no reason to delete it. You can just reuse it for future requests.
__________________
DJ Tsunami is online now
foon
Member
Join Date: Dec 2018
Old 07-22-2020 , 18:05   Re: REST in Pawn 1.2 - HTTP client for JSON REST APIs (Updated 2020/07/16)
Reply With Quote #78

Is there anyway to get the file that was uploaded in "OnImageUploaded". You can pass a value, but you cant pass a string (unless i'm missing something here).
foon is offline
DJ Tsunami
DJ Post Spammer
Join Date: Feb 2008
Old 07-23-2020 , 01:52   Re: REST in Pawn 1.2 - HTTP client for JSON REST APIs (Updated 2020/07/16)
Reply With Quote #79

You can pass a DataPack as value with any data you want.
__________________

Last edited by DJ Tsunami; 07-23-2020 at 01:53.
DJ Tsunami is online now
DJ Tsunami
DJ Post Spammer
Join Date: Feb 2008
Old 09-13-2020 , 06:05   Re: REST in Pawn 1.2 - HTTP client for JSON REST APIs (Updated 2020/07/16)
Reply With Quote #80

Minor update:
  • Added x64 and Mac builds
  • Added JSON decoding flags
  • Added ability to limit send and receive speed (thanks Kxnrl)
  • Set default user agent
  • Updated HTTPStatus enum
  • Updated documentation
Download
__________________

Last edited by DJ Tsunami; 09-13-2020 at 06:10.
DJ Tsunami is online now
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

Forum Jump


All times are GMT -4. The time now is 04:41.


Powered by vBulletin®
Copyright ©2000 - 2020, vBulletin Solutions, Inc.
Theme made by Freecode