lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]

	Hi Laurent

But now ... I'm blocked : my webservices are password protected and I
duno how to pass http authentication thru
	I am not sure but I think the authentication information should be
sent through HTTP headers, thus you cannot do it with,
since it sends a fixed set of headers, unfortunatelly.

But how can I do that in LUA ?
	I'll have to change :-)

About WSDL, I think I can live w/o it providing I'll have to give manually
arguments' type. After being able to communicate with my webservices,
I'll check if I can do something smarter ;D
	For now you can try patching to send the
appropriate headers.  LuaSocket provides functions to deal with base64
encoding.  Follows a suggestion:

-- Untested code!
local function call(args)
	local request_sink, tbody = ltn12.sink.table()
	local headers = {                         -- added lines start here !
		["Content-Type"] = content_type_header,
		["content-length"] = tostring(request_body:len()),
		["SOAPAction"] = soap_action,
	if args.headers then
		for key, val in pairs (args.heders) do
			headers[key] = val
	end                                         -- added lines end here !
	local url = {
		headers = headers,                      -- also change this line!
-- End of untested code!

	This way you can pass to whatever headers
you want and also override the default ones.  But I think you'll have
to encode the login and password.  According to Wikipedia example
and LuaSockets' documentation for http.request()
(, you'll
have to encode the login, a colon and the password, and give it preceeded
by the string "Basic " as the parameter of Authentication header.
I think the following lines will make it work:

-- Untested code!
local mime = require"mime"
local client = require"soap.client" {
	headers = {
		Authorization = "Basic "..mime.b64 (login..':'..password),
	... -- add your arguments
-- End of untested code!

	It seems there is a mistype in LuaSocket's docs; it
says the header name is "authentication", while the RFC 2068
( only mentions "authorization".
	Please, tell me if it works.  I'll be glad to improve LuaSOAP
this way.