[英]Getting 401 error when trying to read file from sharepoint repository
I have been using this code to read in a file from a document repository in sharepoint: 我一直在使用以下代码从sharepoint中的文档存储库中读取文件:
WebResponse objResponse;
WebRequest objRequest = System.Net.HttpWebRequest.Create("http://servername/realestate/SiteAssets/navigation.txt");
objRequest.Timeout = 10000;
objRequest.UseDefaultCredentials = true;
objRequest.Proxy.Credentials = objRequest.Credentials;
objResponse = (WebResponse)objRequest.GetResponse();
using (StreamReader sr = new StreamReader(objResponse.GetResponseStream()))
{
navBar = sr.ReadToEnd();
sr.Close();
}
I just migrated to a new environment, and I am getting a 401 unauthorized error with this code - but, instead of using servername, I am now using hostname (since the new environment has a domain assigned to it). 我刚刚迁移到新环境,此代码出现401未经授权的错误-但是,我现在不使用服务器名,而是使用主机名(因为新环境已分配了域)。 How can I navigate this issue, even though I am now using a host in my HttpWebRequest object?
即使我现在在HttpWebRequest对象中使用主机,也该如何解决此问题? And, if this should not be causing the issue, I would like to hear recommendations as well.
而且,如果这不应该引起问题,我也想听听建议。 Thanks.
谢谢。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.