简体   繁体   English

Perl HTTP守护程序服务器-读取POST JSON正文

[英]Perl HTTP Daemon Server- Reading POST JSON body

I was using HTTP::Daemon to create a http server for my API. 我正在使用HTTP :: Daemon为我的API创建一个http服务器。 With the help of following example and doc , I was able to create a basic HTTP server. 借助以下示例doc ,我能够创建一个基本的HTTP服务器。

However, my API should accepts JSON as a body in post request to the server. 但是,我的API应该在向服务器发布请求后接受JSON作为正文。 So, I need to read the JSON so that I can process it. 因此,我需要阅读JSON,以便可以对其进行处理。 I know, how to read url param $r->uri->query_form(); 我知道,如何读取网址参数$r->uri->query_form();

Is there a way to read POST JSON? 有没有办法读取POST JSON?

use JSON;
use Data::Dumper;
my $json = decode_json($r->content);
print Dumper $json;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM