我有一个 web api 2.0 设置,它在内部调用一个远程 url,这个代码适用于 PC,但不适用于 Apple Mac 浏览器,如 FireFox;他们收到 401 错误。任何帮助将不胜感激!
有问题的代码是:
private static XmlDocument GetXml(string searchCriteria)
{
if (searchCriteria == null) throw new ArgumentNullException(nameof(searchCriteria));
var sUrl = "https://a_remote_classic_asp_service_layer/service.asp?";
var appendUrl = "&sh=N&sp=Y&sr=N";
string fullUrl = $"{sUrl}{searchCriteria}{appendUrl}";
string searchParms = $"{searchCriteria}{appendUrl}";
var document = new XmlDocument();
document.PreserveWhitespace = false;
using (((WindowsIdentity)HttpContext.Current.User.Identity).Impersonate())
{
var request = WebRequest.Create(fullUrl);
request.Credentials = CredentialCache.DefaultCredentials;
request.UseDefaultCredentials = true;
request.PreAuthenticate = true;
using (var stream = request.GetResponse().GetResponseStream())
{
if (stream == null) return document;
using (var reader = XmlReader.Create(stream))
{
document.Load(stream);
}
}
}
return document;
}
谢谢!