Should Webhook JSON mailboxes be encoded in a URL?

The new Relic URL is currently encoding the JSON payload of our websites. We correctly included the required header, but I wonder if this is best practice - or if the JSON payload should be sent unencoded (or even with some other encoding)?

enter image description here

+4
source share
2 answers

Most often, send JSON directly to the request body with a header Content-Type application/json. This is not quite the way New Relic does. Similarly, GitHub payload data is encoded.

/ JSON , , , ,

PHP :

$data = file_get_contents('php://input');
var_dump(json_decode($data));

:

$data = $_POST["payload"];
var_dump(json_decode($data));

, , . GitHub Sinatra:

post '/' do
  push = JSON.parse(params[:payload])
  "I got some JSON: #{push.inspect}"
end

JSON , :

post '/' do
  push = JSON.parse(request.body.read)
  "I got some JSON: #{push.inspect}"
end

, . JSON JSON. JSON , . - :

{
    "notification_id": "akjfd8",
    "events": [ ... ]
}

JSON, , RequestBin. , JSON .

+3

<rant>

, . application/x-www-form-urlencoded, , . -, - - .

JSON, application/json. ?

</rant>

+1

All Articles