我正在尝试使用url(到SharePoint aspx页面)创建WebRequest,并调用GetResponse()方法。我正在通过DefaultCredentials,我甚至已经通过我自己的域用户名和密码,但在GetResponse()方法上,从服务器抛出401 Unauthorized访问错误。我的应用程序支持经理说我必须将服务帐户添加到站点上的所有者组,这不起作用。没有什么工作,我攻击这个代码的每个角度都会返回401错误。请有人可以帮助我并指出正确的方向,或者我错过了应该添加的内容。
私有字符串GetHTMLContents(string url) { string html = string.Empty; try { HttpWebRequest request =(HttpWebRequest)WebRequest.Create(url); request.Method =" GET" ;; request.UseDefaultCredentials = true; request.PreAuthenticate = true; request.Credentials = CredentialCache.DefaultCredentials; WebResponse response = request.GetResponse(); Regex regex = new Regex(" div class = \" emailContentGroup \">(。*)< / div>",RegexOptions.Singleline); Stream stream = null; stream = response.GetResponseStream(); StreamReader reader = new StreamReader(stream); 匹配匹配= regex.Match(reader.ReadToEnd()); html + = match.Groups [0] .Value; } catch(Exception ex){ Response.Write(ex.GetBaseException()); } 返回html; }
谢谢!
<你应该发布到ASP.NET论坛。forums.asp/
Hi,
I'm trying to create a WebRequest with a url (to a SharePoint aspx page)and invoke the GetResponse() method. I am passing through DefaultCredentials, I have even passed through my own domain user name and password but on the GetResponse() method it throws a 401 Unauthorized access error from the server. My App Support manager said I must add the service account to the Owner group on the site, that did not work. Nothing is working, every angle I attack this code it returns a 401 error. Please can someone help me and point me in the right direction, or did I miss something that should be added.
private string GetHTMLContents(string url) { string html = string.Empty; try { HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url); request.Method = "GET"; request.UseDefaultCredentials = true; request.PreAuthenticate = true; request.Credentials = CredentialCache.DefaultCredentials; WebResponse response = request.GetResponse(); Regex regex = new Regex("<div class=\"emailContentGroup\">(.*)</div>", RegexOptions.Singleline); Stream stream = null; stream = response.GetResponseStream(); StreamReader reader = new StreamReader(stream); Match match = regex.Match(reader.ReadToEnd()); html += match.Groups[0].Value; } catch (Exception ex) { Response.Write(ex.GetBaseException()); } return html; }Thank you!
解决方案You should post to the ASP.NET forum.
forums.asp/
更多推荐
WebResponse
发布评论