SharePoint Search Service 415 Unsupported Media Type
I'm attempting to query the search service in JavaScript with JQuery and AJAX. I keep getting a 415 Unsupported media type error back. I'm sending a SOAP envelope to the server through this AJAX command:
$.ajax({
url: "http://groups.company.com/_vti_bin/search.asmx",
beforeSend: function(xhr) {
xhr.setRequestHeader("SOAPAction",
"http://microsoft.com/webservices/OfficeServer/QueryService/GetPortalSearchInfo");
},
type: "POST",
dataType: "text",
data: soapEnv,
complete: processResult,
contentType: "application/text charset=\"utf-8\""
})
I've tried various content types, but I can't see to find an开发者_开发问答y that work. What should it be? Thanks!
Your last line should be:
contentType: "text/xml; charset=\"utf-8\""
It might not be an "incorrect" content-type at all!
SharePoint will return an HTTP 415 is trying to access a SOAP Service on a site with anonymous access because the various SharePoint Web-services require authentication. The body of the result might contain an error message such as: (Why this is returned with a 415 ... I have no idea.)
The following file(s) have been blocked by the administrator: /Lists/MyList/calendar.asp/_vti_bin/Lists.asmx
If this is indeed the case then you can ask SharePoint to offer up a HTTP 401 Challenge by using X-RequestForceAuthentication header (although this is may not required and I have not tested it myself yet, so YMMV :-).
Just make sure to send the appropriate HTTP WWW-Authenticate header. Note that in C# if a Challenge does not occur the header must be manually enabled, as per HttpWebRequest.PreAuthenticate, other environments may have similar issues.
Happy coding.
Also, it doesn't matter if SOAP 1.1 or 1.2 are used with SharePoint 2007/2010. Use the Content-Type: (Don't even think about application/soap-xml
...)
text/xml; charset="UTF-8"
Or 415's will be generated.
精彩评论