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

REST in Pawn 1.3 - HTTP client for JSON REST APIs (Updated 2021/08/22)


Post New Thread Reply   
 
Thread Tools Display Modes
asdfxD
Veteran Member
Join Date: Apr 2011
Old 04-30-2021 , 00:34   Re: REST in Pawn 1.2 - HTTP client for JSON REST APIs (Updated 2021/02/07)
Reply With Quote #101

i have sv_hibernate_when_empty always at 0, with this extension my server goes in hibernation like -> sv_hibernate_when_empty 1

edit: it's not the extension, its eitems.smx or estickers.smx

Last edited by asdfxD; 04-30-2021 at 00:43.
asdfxD is offline
DJ Tsunami
DJ Post Spammer
Join Date: Feb 2008
Location: The Netherlands
Old 06-06-2021 , 07:35   Re: REST in Pawn 1.3 - HTTP client for JSON REST APIs (Updated 2021/06/06)
Reply With Quote #102

Version 1.3 has been released with the following changes:
  • Deprecated HTTPClient methodmap
  • Introduced HTTPRequest methodmap
  • Added ability to append query parameters to the URL
  • Added ability to set the credentials for HTTP Basic authentication
  • Added ability to set the maximum number of redirects to follow
  • Added ability to POST form data
  • Allow user defined 'Accept' and 'Content-Type' headers (thanks Peak)
  • Fixed HTTP/2 timeouts by enforcing HTTP/1.1 for file transfers on Windows
  • Fixed response body being printed to server console during file upload
  • Throw an error when passing empty values to some natives
Download
__________________
Advertisements | REST in Pawn - HTTP client for JSON REST APIs
Please do not PM me with questions. Post in the plugin thread.

Last edited by DJ Tsunami; 06-06-2021 at 07:36.
DJ Tsunami is offline
Deather
New Member
Join Date: Nov 2016
Old 06-07-2021 , 14:07   Re: REST in Pawn 1.3 - HTTP client for JSON REST APIs (Updated 2021/06/06)
Reply With Quote #103

Is it possible to log request?

When I try to send some POST data to my API (Laravel), backend receives empty request (headers and method are correct, but there is no POST data).

Code:
    JSONObject BanJson = new JSONObject();
    BanJson.SetString("nickname", Nickname);
    BanJson.SetString("steam_id", SteamId);
    BanJson.SetInt("type", Type);
    BanJson.SetInt("duration", Duration);
    BanJson.SetString("reason", Reason);
    BanJson.SetString("admin_nickname", AdminNickname);
    BanJson.SetString("admin_steam_id", AdminSteamId); 

    HTTPRequest Request = new HTTPRequest(GetApiURI(ApiEndPoint));
    
    Request.SetHeader("Authorization", "Bearer %s",  GeneralConfig.Token);
    Request.SetHeader("GameServer", "%d", GeneralConfig.ServerId);
    Request.SetHeader("Content-Type", "application/json");
    Request.SetHeader("Accept", "application/json");

    Request.Post(BanJson, OnPlayerBan);
Same request sended by PostMan works correctly...

Last edited by Deather; 06-07-2021 at 15:18.
Deather is offline
DJ Tsunami
DJ Post Spammer
Join Date: Feb 2008
Location: The Netherlands
Old 06-07-2021 , 15:40   Re: REST in Pawn 1.3 - HTTP client for JSON REST APIs (Updated 2021/06/06)
Reply With Quote #104

How are you reading the POST data in Laravel? This works for me with both Postman and REST in Pawn:

PHP Code:
Route::post('/post', function (Request $request) {
    return new 
JsonResponse($request->all());
}); 
__________________
Advertisements | REST in Pawn - HTTP client for JSON REST APIs
Please do not PM me with questions. Post in the plugin thread.

Last edited by DJ Tsunami; 06-07-2021 at 15:41.
DJ Tsunami is offline
Deather
New Member
Join Date: Nov 2016
Old 06-07-2021 , 16:26   Re: REST in Pawn 1.3 - HTTP client for JSON REST APIs (Updated 2021/06/06)
Reply With Quote #105

Laravel:
PHP Code:
Route::post('/test', function (Request $request) {
    return 
response()->json($request->all());
}); 
Simple PHP:
PHP Code:
<?php

$postData 
json_encode($_POST);
$jsonData file_get_contents('php://input');

echo 
$postData;
echo 
$jsonData;

file_put_contents('post.txt'$postData);
file_put_contents('json.txt'$jsonData);

?>
Both solutions receives nothing when requesting from game server.


@edit:
PHP Code:
    Request.AppendFormParam("test""%s""foo");
    
Request.PostForm(OnTestRequest); 
I've used PostForm instead of Post but i still don't know why Post + JSON doesn't work...


@edit-2:
I've saved some backend logs:
PostForm():
PHP Code:
[2021-06-08 14:39:05local.DEBUGContent-Type"application\/x-www-form-urlencoded"  
[2021-06-08 14:39:05local.DEBUGAccept"application\/json"  
[2021-06-08 14:39:05local.DEBUGPath"api\/test2"  
[2021-06-08 14:39:05local.DEBUGMethod"POST"  
[2021-06-08 14:39:05local.DEBUGData: {"test":"foo"}  
[
2021-06-08 14:39:05local.DEBUG$_POST: {"test":"foo"
Post() + JSON
PHP Code:
[2021-06-08 14:41:40local.DEBUGContent-Type"application\/json"  
[2021-06-08 14:41:40local.DEBUGAccept"application\/json"  
[2021-06-08 14:41:40local.DEBUGPath"api\/test2"  
[2021-06-08 14:41:40local.DEBUGMethod"POST"  
[2021-06-08 14:41:40local.DEBUGData: []  
[
2021-06-08 14:41:40local.DEBUG$_POST: [] 
Post() + JSON (Content-Type: application/x-www-form-urlencoded)
PHP Code:
[2021-06-08 14:42:42local.DEBUGContent-Type"application\/x-www-form-urlencoded"  
[2021-06-08 14:42:42local.DEBUGAccept"application\/json"  
[2021-06-08 14:42:42local.DEBUGPath"api\/test2"  
[2021-06-08 14:42:42local.DEBUGMethod"POST"  
[2021-06-08 14:42:42local.DEBUGData: []  
[
2021-06-08 14:42:42local.DEBUG$_POST: [] 
It will be really nice to log what extension sends to backend (to be sure that isn't extension bug)...

Last edited by Deather; 06-08-2021 at 10:52.
Deather is offline
DJ Tsunami
DJ Post Spammer
Join Date: Feb 2008
Location: The Netherlands
Old 06-13-2021 , 06:01   Re: REST in Pawn 1.3 - HTTP client for JSON REST APIs (Updated 2021/06/06)
Reply With Quote #106

Quote:
Originally Posted by Deather View Post
It will be really nice to log what extension sends to backend (to be sure that isn't extension bug)...
I've attached debug builds for Linux and Windows. It would also be useful to know what webserver you're using (Apache / nginx / Caddy?), and which version.

Laravel should automatically fill the Request object if the Content-Type is application/json. PHP's $_POST variable will only be filled when posting form data.
Attached Files
File Type: zip Linux.zip (4.35 MB, 159 views)
File Type: zip Windows.zip (1.49 MB, 121 views)
__________________
Advertisements | REST in Pawn - HTTP client for JSON REST APIs
Please do not PM me with questions. Post in the plugin thread.

Last edited by DJ Tsunami; 08-24-2021 at 13:00.
DJ Tsunami is offline
digin
Member
Join Date: Nov 2019
Old 06-19-2021 , 21:54   Re: REST in Pawn 1.3 - HTTP client for JSON REST APIs (Updated 2021/06/06)
Reply With Quote #107

i don't know why but after i move to my new VPS the PUT think is not working, always return HTTPStatus_Invalid = 0.

My Old VPS : Plesk Panel (PHP 7.4.20 + Server API FPM/FastCGI)
My New VPS : Cyberpanel (PHP 7.4.20 + Server API LiteSpeed V7.9)

"REST in Pawn" (1.2.3) by Tsunami: Provides HTTP and JSON natives for plugins

i test with Postman it's working, but the plugin always return HTTPStatus_Invalid = 0.

anyone experiencing the same thing?

Last edited by digin; 06-19-2021 at 21:58.
digin is offline
digin
Member
Join Date: Nov 2019
Old 06-19-2021 , 22:33   Re: REST in Pawn 1.3 - HTTP client for JSON REST APIs (Updated 2021/06/06)
Reply With Quote #108

i try with Debug builds from you above

PHP Code:
=== InfoSTATEINIT => CONNECT handle 0xde922140line 1646 (connection #-5000)

=== InfoFound bundle for host subdomain.domain.com0xde9070c0 [can multiplex]

=== 
InfoRe-using existing connection! (#0) with host subdomain.domain.com

=== InfoConnected to subdomain.domain.com (194.XXX.XX.XXport 443 (#0)

=== InfoSTATECONNECT => DO handle 0xde922140line 1700 (connection #0)

=== Infohttp2_send len=194

=== Infoh2 header: :method:PUT

=== Infoh2 header: :path:/api/retakes/76561199145573335

=== Infoh2 header: :scheme:https

=== Infoh2 header: :authority:subdomain.domain.com

=== Infoh2 headeruser-agent:sm-ripext/1.3.0

=== Infoh2 headeraccept-encoding:deflategzip

=== Infoh2 headeraccept:application/json

=== Infoh2 headercontent-type:applicaton/json

=== Infohttp2_send request allowed 1 (easy handle 0xde922140)

=== 
InfoUsing Stream ID(easy handle 0xde922140)

==> 
Send header
PUT 
/api/retakes/76561199145573335 HTTP/2

Host
subdomain.domain.com

user
-agentsm-ripext/1.3.0

accept
-encodingdeflategzip

accept
application/json

content
-typeapplicaton/json




=== InfoSTATE: DO => DO_DONE handle 0xde922140line 1935 (connection #0)

=== InfoSTATEDO_DONE => PERFORM handle 0xde922140line 2056 (connection #0)

=== Infohttp2_send len=306

=== Infodata_source_read_callbackreturns 306 bytes stream 3

=== Infohttp2_send returns 306 for stream 3

==> Send data
{"pistolround_ct""weapon_usp_silencer""primary_ct""weapon_ak47""secondary_ct""weapon_usp_silencer""smg_ct""weapon_ump45""awp_ct"0"scout_ct"0"pistolround_t""weapon_glock""primary_t""weapon_ak47""secondary_t""weapon_glock""smg_t""weapon_ump45""awp_t"0"scout_t"0}
=== 
Infoh2_process_pending_inputAll data in connection buffer processed

=== Infodata_source_read_callbackreturns 0 bytes stream 3

=== Infohttp2_recveasy 0xde922140 (stream 3win 33554278/33554432

=== Infonread=13

=== Infoon_frame_recv() header 3 stream 3

=== InfoGot frame type 3 for stream 3!

=== 
Infoon_stream_close(), PROTOCOL_ERROR (err 1), stream 3

=== InfoRemoved stream 3 hash!

=== 
Infoh2_process_pending_inputAll data in connection buffer processed

=== Infohttp2_recveasy 0xde922140 (stream 0win 33554278/4294967295

=== Infoh2_process_pending_inputAll data in connection buffer processed

=== InfoHTTP/2 stream 0 was not closed cleanlyPROTOCOL_ERROR (err 1)
*********&
#1928;***************************    %******************ܠ******************P*********************************************`*************************** ***************************p***************************,***************************H***************************蠓*********************************************|******************************************************<***************************Ǥ*********ވ***************************`***************************@!******************@Ȓ*********X***************************R***************************
=== Infomulti_done

=== Infostopped the pause stream!

=== 
InfoConnection #0 to host subdomain.domain.com left intact

=== InfoExpire cleared (transfer 0xde922140

Last edited by digin; 06-19-2021 at 22:35.
digin is offline
CrazyHackGUT
AlliedModders Donor
Join Date: Feb 2016
Location: Izhevsk, Russia
Old 08-02-2021 , 14:26   Re: REST in Pawn 1.3 - HTTP client for JSON REST APIs (Updated 2021/06/06)
Reply With Quote #109

It is possible to send non-chunked request body? Sometimes for shared web-hostings it breaks everything, unfortunately.
__________________
My english is very bad. I am live in Russia. Learning english language - very hard task for me...
CrazyHackGUT is offline
Send a message via ICQ to CrazyHackGUT Send a message via Skype™ to CrazyHackGUT
DJ Tsunami
DJ Post Spammer
Join Date: Feb 2008
Location: The Netherlands
Old 08-24-2021 , 11:48   Re: REST in Pawn 1.3 - HTTP client for JSON REST APIs (Updated 2021/06/06)
Reply With Quote #110

Quote:
Originally Posted by CrazyHackGUT View Post
It is possible to send non-chunked request body? Sometimes for shared web-hostings it breaks everything, unfortunately.
Have you tried
PHP Code:
request.SetHeader("Transfer-Encoding"""); 
? I'm not sure if it will work, since it puts a space after the colon.
__________________
Advertisements | REST in Pawn - HTTP client for JSON REST APIs
Please do not PM me with questions. Post in the plugin thread.
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:36.


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