我已经获得了 RESTful Web 服务,可以将数据推送到另一个应用程序的远程数据库中.我需要通过将 JSON 格式的数据作为 GET/POST 参数发送到 Web 服务来调用这些服务以从 PostgreSQL 数据库推送数据.是否可以从首先将数据推送到我的数据库的 PostgreSQL 函数(定期)调用这些 Web 服务,或者编写 JAVA 代码来调用这些在 PostgreSQL 数据库上运行查询的 Web 服务并调用 Web 服务将它们传递给远程数据库.
I have been provided RESTful web services to push data into a remote DB of another application. I need to call these services to push data from PostgreSQL DB by sending data in JSON format as GET/POST parameters to the web service. Is it possible to call these web services from the PostgreSQL functions (periodically) which push data into my database in the first place, or write JAVA code to call these web services that run queries on PostgreSQL database and call web services to pass them to the remote DB.
推荐答案是的,这是可能的,虽然不是直接来自 Postgresql 本身.我不了解 Java,但最快的方法是将 plperlu 与 REST::Client 包一起使用,例如:
Yes, it is possible, althought not directly from Postgresql itself. I don't know about Java but the fastest way is to use plperlu with REST::Client package, e.g.:
CREATE OR REPLACE FUNCTION restful.put(auri character varying, ajson_text text) RETURNS text LANGUAGE plperlu SECURITY DEFINER AS $function$ use REST::Client; use Encode qw(encode); my $client = REST::Client->new(); $client->getUseragent()->proxy( 'https', 'some-proxy/' ); # use for proxy authentication $client->addHeader('Content-Type', 'application/json'); # headers $client->POST( $_[0], encode('UTF-8', $_[1])); # encoding return $client->responseContent(); $function$更多推荐
从 PostgreSQL 过程/函数调用 RESTful Web 服务
发布评论