WebResponse

编程入门 行业动态 更新时间:2024-10-25 20:28:53
本文介绍了WebResponse - 401的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在尝试使用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

本文发布于:2023-11-10 03:07:04,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1574181.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:WebResponse

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!