-
Notifications
You must be signed in to change notification settings - Fork 39
/
post_example.pl
48 lines (38 loc) · 1.16 KB
/
post_example.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
:- use_module(library(http/thread_httpd)).
:- use_module(library(http/http_dispatch)).
:- use_module(library(http/http_error)).
:- use_module(library(http/html_write)).
% we need this module from the HTTP client library for http_read_data
:- use_module(library(http/http_client)).
:- http_handler('/', web_form, []).
server(Port) :-
http_server(http_dispatch, [port(Port)]).
/*
browse http://127.0.0.1:8000/
This demonstrates handling POST requests
*/
web_form(_Request) :-
reply_html_page(
title('POST demo'),
[
form([action='/landing', method='POST'], [
p([], [
label([for=name],'Name:'),
input([name=name, type=textarea])
]),
p([], [
label([for=email],'Email:'),
input([name=email, type=textarea])
]),
p([], input([name=submit, type=submit, value='Submit'], []))
])]).
:- http_handler('/landing', landing_pad, []).
landing_pad(Request) :-
member(method(post), Request), !,
http_read_data(Request, Data, []),
format('Content-type: text/html~n~n', []),
format('<p>', []),
portray_clause(Data),
format('</p><p>========~n', []),
portray_clause(Request),
format('</p>').