Skip to content

Commit 4d31fd1

Browse files
committed
Add example clients for the Web API.
1 parent 5410c35 commit 4d31fd1

File tree

3 files changed

+45
-0
lines changed

3 files changed

+45
-0
lines changed

web-api-clients/README

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
This directory contains example clients for the Web API in several
2+
programming languages. More information about the Web API is available
3+
at:
4+
5+
http://www.it.uc3m.es/jaf/html2xhtml/web-api.html
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#!/bin/sh
2+
3+
if [ ! $# -eq 1 ]
4+
then
5+
echo "Input HTML file name is expected as a command-line parameter" >&2
6+
else
7+
curl --data-binary @$1 -H "Content-Type: text/html" http://www.it.uc3m.es/jaf/cgi-bin/html2xhtml.cgi
8+
fi

web-api-clients/python/html2xhtml.py

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#!/usr/bin/python
2+
3+
#
4+
# Example client script for the html2xhtml service.
5+
#
6+
7+
import sys
8+
import httplib, urllib
9+
10+
headers = {"Content-type": "text/html",
11+
"Accept": "application/xhtml+xml"}
12+
params = urllib.urlencode({'tablength': 4,
13+
'linelength': 100,
14+
'output-charset': 'UTF-8'})
15+
url = "/jaf/cgi-bin/html2xhtml.cgi?" + params
16+
17+
# read the input HTML file (first command-line argument)
18+
in_file = open(sys.argv[1], 'r')
19+
in_data = in_file.read()
20+
21+
# connect to the server and send the POST request
22+
conn = httplib.HTTPConnection("www.it.uc3m.es:80")
23+
conn.request("POST", url, in_data, headers)
24+
response = conn.getresponse()
25+
26+
# show the result
27+
if response.status == 200:
28+
print response.read()
29+
else:
30+
print >> sys.stderr, response.status, response.reason
31+
32+
conn.close()

0 commit comments

Comments
 (0)