0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

JSON データを POST で受けるテストサーバを作る

Posted at

IoTデータを受けるサーバでは、API として JSON データを POST するものが多い。
ちゃんと JSON データが送られているかな? とデバッグする時に、自前でちゃちゃっとテストサーバーを作ってみる。

PHP スクリプト


<!DOCTYPE HTML>
<HTML><HEAD><META CHARSET=UTF-8><TITLE></TITLE></HEAD>
<BODY></BODY>
<PRE>
<?php

// $data = $_POST['data'];
// echo $data;

$json = file_get_contents("php://input");
$contents = json_decode($json, true);
var_dump($contents);

?>
</PRE></BODY></HTML>

最初は


// $data = $_POST['data'];
// echo $data;

としていたが、JSONのPOSTは通常のPOSTメソッドじゃないということで、上記のように書き直し。

使い捨てのスクリプトだったのだけど、これ便利、超絶便利、という声があったので公開しておきます。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?