Raised This Month: $13 Target: $400
 3% 

REST in Pawn 1.2 - HTTP client for JSON REST APIs (Updated 2020/06/21)


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 offline
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 06:23.


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