我正在用 asp.net 和 c# 开发一个 web 服务,它显示了poinstreak.com上受密码保护的 XML 文件的内容。我的问题是我似乎无法使身份验证正常工作(我不断获得 401 状态)。关于如何解决这个问题的任何建议?
protected void dataBind()
{
//Variables
string xmlfile = "http://www.pointstreak.com/xml/GET/schedule_11200.xml";
string xslfile = "/StyleSheet/XSLT/xslForGETMatches.xsl";
//Credentials
NetworkCredential myCred = new NetworkCredential("username", "password");
CredentialCache myCache = new CredentialCache();
myCache.Add(new Uri(xmlfile), "Basic", myCred);
//Set the credentials on the XmlUrlResolver object
XmlUrlResolver resolver = new XmlUrlResolver();
resolver.Credentials = myCache;
//XSL Transformation
XslCompiledTransform xslt = new XslCompiledTransform();
xslt.Load(xslfile, XsltSettings.Default, resolver);
StringBuilder outfile = new StringBuilder();
XmlWriterSettings settings = xslt.OutputSettings.Clone();
settings.CheckCharacters = false;
xslt.Transform(xmlfile, XmlWriter.Create(outfile, settings));
xmlToHtmlOutput.Text = outfile.ToString(); //An ASP Label
}