File: http.lua

package info (click to toggle)
lua-soap 1.0b-5
  • links: PTS
  • area: main
  • in suites: lenny
  • size: 112 kB
  • ctags: 38
  • sloc: sh: 66; makefile: 34
file content (33 lines) | stat: -rw-r--r-- 963 bytes parent folder | download | duplicates (2)
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
---------------------------------------------------------------------
-- SOAP over HTTP.
-- See Copyright notice in license.html
-- $Id: http.lua,v 1.1 2004/03/24 19:27:37 tomas Exp $
---------------------------------------------------------------------

require"luasocket"
require"soap"

local post = socket.http.post

soap.http = {}

---------------------------------------------------------------------
-- Call a remote method.
-- @param url String with the location of the server.
-- @param namespace
---------------------------------------------------------------------
function soap.http.call (url, namespace, method, entries, headers)
	local body, headers, code, err = post {
		url = url,
		body = soap.encode (namespace, method, entries, headers),
		headers = {
			["Content-type"] = "text/xml",
			["SOAPAction"] = '"'..method..'"',
		},
	}
	if tonumber (code) == 200 then
		return soap.decode (body)
	else
		error ((err or code).."\n\n"..body)
	end
end