Http通过请求发布请求

问题描述 投票:0回答:1

我正在尝试通过序言向其他rest api发出发布请求。 (如果我要在js中执行):

body={

login="login",

passsword="password"

}

axios.post("http://localhost:5000",body);

我不是试图发布TO序言,而是试图将FROM序言发布到另一个api。

我不知道如何将正文添加为json并将Content-Type设置为application / json。

这是我到目前为止提出的:

% Bibliotecas
:- use_module(library(http/thread_httpd)).
:- use_module(library(http/http_dispatch)).
:- use_module(library(http/http_parameters)).
:- use_module(library(http/http_ssl_plugin)).
:- use_module(library(http/http_open)).
:- use_module(library(http/http_json)).

% Routes
:- http_handler('/auth', auth, []).
:- http_handler('/send_file_post', send_file_post, []).

% Cria��o de servidor HTTP no porto 'Port'
server(Port) :-
        http_server(http_dispatch, [port(Port)]).

auth(Request) :-
  http_read_json(Request, DictIn,[json_object(dict)]),
   format(user_output,"Request is: ~p~n",[Request]),
   format(user_output,"DictIn is: ~p~n",[DictIn]),
   DictOut=DictIn,
   reply_json(DictOut),

   http_client:http_post('http://localhost:5000/api/users/authenticate', DictOut,Reply, [content("application/json")]),
  http_read_data(Reply, Data, []).

要进一步说明:

我向我的prolog http服务器发出发布请求,在它的主体中,我有一封电子邮件和一个密码。我的最终目标是使用相同的电子邮件/密码向另一个api发出第二个发布请求。

有什么建议吗?

http post prolog swi-prolog
1个回答
0
投票
您可以使用http_post/4

https://www.swi-prolog.org/pldoc/doc_for?object=http_post/4

http_post([ protocol(http), host(localhost), port(5000), path('/mypostpage') ], form_data([ login = myusername, password = pass123 ]), Reply, []).

将发帖请求至http://localhost:5000/mypostpage
© www.soinside.com 2019 - 2024. All rights reserved.