从 PostgreSQL 过程/函数调用 RESTful Web 服务

编程入门 行业动态 更新时间:2024-10-23 07:24:18
本文介绍了从 PostgreSQL 过程/函数调用 RESTful Web 服务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我已经获得了 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 服务

本文发布于:2023-10-16 12:00:24,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1497496.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:函数   过程   PostgreSQL   RESTful   Web

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!