Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

POST don't send any params #17

Closed
mwoznowski opened this issue Mar 29, 2019 · 7 comments
Closed

POST don't send any params #17

mwoznowski opened this issue Mar 29, 2019 · 7 comments

Comments

@mwoznowski
Copy link

mwoznowski commented Mar 29, 2019

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.
https://pastebin.com/0e2ecBdk
Output JSON file:
[[],[],[]]
Plugin:
https://pastebin.com/5zbUtY8U

@indietyp
Copy link

excerpt from www.php.net/manual/en/reserved.variables.post.php

An associative array of variables passed to the current script via the HTTP POST method when using application/x-www-form-urlencoded or multipart/form-data as the HTTP Content-Type in the request.

as you can see the sent data is json and not x-www-form-urlencoded therefore $_POST is empty.

@mwoznowski
Copy link
Author

header("Content-Type: application/x-www-form-urlencoded");

Dont give result

@ErikMinekus
Copy link
Owner

ErikMinekus commented Mar 31, 2019

To get the request body in PHP:

$body = file_get_contents('php://input');

Then use json_decode to parse it as JSON.

@indietyp
Copy link

indietyp commented Apr 1, 2019

setting the header does not implicitly change the format of the request body.

an example:
A JSON payload looks like this:

{
	"a": "b"
}

while an application/x-www-form-urlencoded looks like this:

a=b

as you can see those are inherently different - changing the header won't change the actual body content and formatting.

@mwoznowski
Copy link
Author

To get the request body in PHP:

$body = file_get_contents('php://input');

Then use json_decode to parse it as JSON.

This resolve is good and works :) Thanks

@udee297
Copy link

udee297 commented May 29, 2020

hi,
i got same issue,
on my web server i already use this
$jsonString = file_get_contents("php://input");
$myFile = "player-".date('his', time()).".json";
file_put_contents($myFile,$jsonString);

and plugin using this
HTTPClient httpClient;
httpClient = new HTTPClient(APIURL);
JSONObject player = new JSONObject();
player.SetString("id", authid);
player.SetString("ip", ip_address);
httpClient.Post("api.php", player, OnPlayerLoad, client);
delete player;

but i still got blank on my web server..

but if i use curl on my gameserver, its working fine
curl -d '{"id":"327mm1327821378","ip":"123.123.123.11"}' http://website.com/api.php
i can see json file on my web

@udee297
Copy link

udee297 commented May 29, 2020

@ErikMinekus its correct right?

Repository owner locked as resolved and limited conversation to collaborators Jun 21, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants