lua-users home
lua-l archive

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

I am attempting to write my first lua script with the aim of retrieving some data from a SharePoint list using the GetListItems operation from the build-in Lists.asmx web service.

Googleing led me to LuaSocket and I think, that the script below succedes in sending my request to the SharePoint web service but the response seems to indicate that I need NTLM authorization in order to get the data that I want.

Is it possible to use NTLM authorization with LuaSocket or are there other ways to to set up authentication. I have tried to add "user:pass@" in the ULR, but this did not change the response from the SharePoint site.

Is LuaSocket the correct choice for communicating with a SharePoint web service or should I be looking at something else entirely?

Here is my lua script:

-- Get data from SharePoint site
local http = require("socket.http")
local ltn12 = require("ltn12")
local io = require("io")

local body = [[
<soap:Envelope xmlns:soap=""; xmlns:soap1="";>
<Query><Where><Eq><FieldRef Name='Field'/><Value Type='Number'> 1234 </Value></Eq></Where></Query>
<ViewFields><FieldRef Name='ID' /><FieldRef Name='Field' /></ViewFields>

r, c, h = http.request {
	url = "http://my/sharepoint/site/_vti_bin/lists.asmx";,
	method = "POST",
	sink = ltn12.sink.file(io.stdout),
	source = ltn12.source.string(body),
	headers = {
		["Content-Length"] = tostring(body:len()),
		["Content-Type"] = "application/soap+xml;charset=UTF-8",
["SOAPAction"] = "\"\"";,
		["Connection"] = "Keep-Alive",

-- Copied from
-- Print anything - including nested tables
function table_print (tt, indent, done)
  done = done or {}
  indent = indent or 0
  if type(tt) == "table" then
    for key, value in pairs (tt) do
      io.write(string.rep (" ", indent)) -- indent it
      if type (value) == "table" and not done [value] then
        done [value] = true
        io.write(string.format("[%s] => table\n", tostring (key)));
        io.write(string.rep (" ", indent+4)) -- indent it
        table_print (value, indent + 7, done)
        io.write(string.rep (" ", indent+4)) -- indent it
        io.write(string.format("[%s] => %s\n",
            tostring (key), tostring(value)))
    io.write(tt .. "\n")


-- End of script

Running my script yields:

  [microsoftsharepointteamservices] =>
  [www-authenticate] => NTLM
  [date] => Mon, 17 Sep 2012 12:05:16 GMT
  [x-powered-by] => ASP.NET
  [content-length] => 0
  [server] => Microsoft-IIS/7.0

I can successfully send the same request to the SharePoint site using soapUI and in return I get the following headers:

Content-Length	697
#status#	HTTP/1.1 200 OK
Set-Cookie	WSS_KeepSessionAuthenticated=80; path=/
Server	Microsoft-IIS/7.0
X-Powered-By	ASP.NET
Cache-Control	private, max-age=0
X-AspNet-Version	2.0.50727
Vary	Accept-Encoding
Date	Mon, 17 Sep 2012 11:52:24 GMT
Content-Encoding	gzip
Content-Type	application/soap+xml; charset=utf-8

and a soap:Envelope containing the response data.