Hello, can somebody help me, how send post webrequest with body json. I read manual on site. When I send body param=value¶m=value - it's OK, but if I send Json - it's not OK) sorry for my English if I write with errors:)
Posting web request with JSON body?
You can provide your code as start
Orange
You can provide your code as start
[ConsoleCommand("webs")]
void API_UpdOnline(ConsoleSystem.Arg arg)
{
Dictionary Players = new Dictionary();
foreach (var player in BasePlayer.activePlayerList)
{
Players.Add(player.UserIDString, player.displayName);
}
var body = JsonConvert.SerializeObject(Players);
webrequest.Enqueue("http://moder.angryrust.ru/cfg/proc.php", body , (code, response) => { GetCallback(code, response); }, this, Core.Libraries.RequestMethod.POST);
}
$_POST - is empty
But if body param=value¶m=value - its ok)
Merged postHelp pls ))
I don't see anything on our end that would prevent it from posting, are you sure nothing is received for the body?
It's normal for $_POST to be empty for JSON content. You need to read the raw POST data.Qbis[ConsoleCommand("webs")] void API_UpdOnline(ConsoleSystem.Arg arg) { Dictionary Players = new Dictionary(); foreach (var player in BasePlayer.activePlayerList) { Players.Add(player.UserIDString, player.displayName); } var body = JsonConvert.SerializeObject(Players); webrequest.Enqueue("http://moder.angryrust.ru/cfg/proc.php", body , (code, response) => { GetCallback(code, response); }, this, Core.Libraries.RequestMethod.POST); }
$_POST - is empty
But if body param=value¶m=value - its ok)
Merged post
Help pls ))
austinv900
It's normal for $_POST to be empty for JSON content. You need to read the raw POST data.
<?php
$data = file_get_contents("php://input");
$json = json_decode($data);
?>It's?
Correct