View Single Post
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