VB(exeファイル)からJSONをPOSTするにはどのようにしたらよいでしょうか?
受け取る側の実装は次の通りです。
PHP
1$json_string = file_get_contents('php://input'); 2$arr = json_decode($json_string, true); 3foreach ($arr as $line) { 4 $save .= $line["userId"]."\t".$line["dakokuTime"]."\n"; 5} 6file_put_contents("data.tsv", $save, FILE_APPEND);
WEBを検索してみましたが、ぴったり該当する記事を見つけることができませんでした。
JSONをPOSTするのは一般的ではないのでしょうか?
PHPだとやり方は分かるのですが…
PHP
1$url = 'http://example.com/server.php'; 2 3$json = '[{"userId":"100", "dakokuTime":"201510261157"}, {"userId":"101", "dakokuTime":"201510261158"}]'; 4 5$tmp['http']['method'] = 'POST'; 6$tmp['http']['header'] = 'Content-Type: application/json'; 7$tmp['http']['content'] = $json; 8$tmp['http']['ignore_errors'] = true; 9$context = stream_context_create($tmp); 10 11$response = file_get_contents($url, false, $context);
クライアント側はWindowsで、実際には(クライアント側では)WEBサーバは動作していないものとします。
よろしくお願いいたします。
なお、他にもっと良いやり方があれば教えてください。
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2015/10/27 03:43