Posting web request with JSON body?
Hello, can somebody help me, how send post webrequest with body json. I read manual on site. When I send body param=value&param=value - it's OK, but if I send Json - it's not OK) sorry for my English if I write with errors:)
You can provide your code as start
5ba216a6d7f65.png 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&param=value - its ok)

Merged post

Help pls ))
I don't see anything on our end that would prevent it from posting, are you sure nothing is received for the body?
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&param=value - its ok)

Merged post

Help pls ))
It's normal for $_POST to be empty for JSON content. You need to read the raw POST data.
5b5bc71c51a3f.png 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