I'm attempting to do a pretty straightforward query to the list.asmx web service and I keep getting a 401 error. I've spent a couple of hours attempting to solve it with no luck.
My jQuery Code:
$.ajax({
type: "POST",
url: "http://devsp2:3050/_vti_bin/lists.asmx/GetList",
data: '{"listName":"Site Pages"}',
contentType: "application/json; charset=utf-8",
dataType: "json",
xhrFields: {
withCredentials: true
}
})
Error Details:
When I execute the code on a test page with a simple button click it prompts me to authenticate. However it asks me to authenticate to the servername.company.com and not the headername I passed.
Firebug returns:
{"Message":"There was an error processing the request.","StackTrace":"","ExceptionType":""}
Fiddler returns (Raw):
HTTP/1.1 401 Unauthorized Content-Type: text/html; charset=utf-8 Server: Microsoft-IIS/7.5 SPRequestGuid: 9ed17429-0633-4bb8-82dd-fb086b86977f WWW-Authenticate: NTLM X-Powered-By: ASP.NET MicrosoftSharePointTeamServices: 14.0.0.4762 Date: Thu, 03 May 2012 19:43:08 GMT Content-Length: 16 Proxy-Support: Session-Based-Authentication
401 UNAUTHORIZED
soapUI
When I query the same web service using the same credentials with soapUI, it works great.
Attempted Solutions:
- Registry Edits
- BackConnectionHostNames
- DisableLoopbackCheck
- withCredentials in jQuery
Updated: Successful Solution
Thanks to @Mark D Anderson for pointing me in the right direction. The below code works. Credit to Jan Tielen as well (http://weblogs.asp.net/jan/archive/2009/04/09/calling-the-sharepoint-web-services-with-jquery.aspx)
var soapEnv =
"<soapenv:Envelope xmlns:soapenv='http://schemas.xmlsoap.org/soap/envelope/'> \
<soapenv:Body> \
<GetListCollection xmlns='http://schemas.microsoft.com/sharepoint/soap/'> \
</GetListCollection> \
</soapenv:Body> \
</soapenv:Envelope>";
$.ajax({
url: "http://devsp2:3050/_vti_bin/lists.asmx",
type: "POST",
dataType: "xml",
data: soapEnv,
contentType: "text/xml; charset=\"utf-8\""
});