http_read_data(Request, Data, []) 将数据发布到 prolog

问题描述

我正在尝试制作一个 prolog api,在那里我从另一个程序调用给定的 prolog 链接。经过多次尝试和学习prolog,这是我能写出的最好的代码版本

#!/usr/bin/env swipl
:- use_module(library(http/thread_httpd)).
:- use_module(library(http/http_dispatch)).
:- use_module(library(http/http_client)).
:- initialization main.
:- http_handler(/,index,[]).
:- http_handler('/test',test,[]).
:- http_handler('/reply',reply,[]).

index(_Request) :-
      format('Content-type: text/plain~n~n'),format('Hello World!~n').

test(_Request) :-
      format('Content-type: text/plain~n~n'),format('This is another test,trying to make multiple links!~n').

reply(Request) :-
      member(method(post),Request),!,http_read_data(Request,Data,[]),format('Content-type: text/plain~n~n'),format('This is where the data should be displayed!~n').
      /*print(Data).*/
      

main :-
  http_server(http_dispatch,[port(3000)]),thread_get_message(quit).

回复的主要功能给了我一个内部服务器错误和语法错误:invalid_uri_query 当我省略这一行时: http_read_data(请求,数据,[]), 一切正常,所以我相信有一些我无法弄清楚的事情。

注意:我发送的数据只是一个字符串,通过以下 Laravel 编写的代码:

$ch = curl_init('http://localhost:3000/reply');
curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);
curl_setopt($ch,CURLOPT_POSTFIELDS,$jsonStr);

// execute!
$response = curl_exec($ch);

// close the connection,release resources used
curl_close($ch);

此代码适用于其他两个页面索引和测试。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)