Siteminder身份验证

Siteminder身份验证

我正在尝试编写一些代码以连接到使用Siteminder身份验证的HTTPS站点。

我一直收到401。有什么想法吗?

我在这里阅读了一些不同的内容,但似乎没有什么真正有用的。我还使用Fiddler / Firefox Tamper监听正在发生的事情。

到目前为止,这是我有关代码的内容:

try
        {

            Uri uri = new Uri("https://websiteaddresshere");
            HttpWebRequest request = (HttpWebRequest)WebRequest.Create(uri) as HttpWebRequest;

            request.Accept = "text/html, application/xhtml+xml, */*";

            request.UserAgent = "Mozilla/5.0 (Windows NT 6.1; WOW64; Trident/7.0; rv:11.0) like Gecko";
        //    request.Connection = "Keep-Alive";
           // request.Method = "Get";
           // request.Accept = "text";
            request.AllowAutoRedirect = true;
            request.AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate;

            Cookie emersoncookie = new Cookie("SMCHALLENGE",  "YES");
            emersoncookie.Domain = "mydomain";
            emersoncookie.Path = "/";




           // authentication
            var cache = new CredentialCache();
            cache.Add(uri, "False", new NetworkCredential("myusername", "mypassword"));

            request.Credentials = cache;


            // response.
            using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())
            {
                using (Stream stream = response.GetResponseStream())
                {
                    XmlTextReader reader = new XmlTextReader(stream);
                    MessageBox.Show(stream.ToString());
                }
            }

        }
        catch (WebException exception)
        {
            string responseText;

            using (var reader = new StreamReader(exception.Response.GetResponseStream()))
            {
                responseText = reader.ReadToEnd();
                MessageBox.Show(responseText.ToString());
            }
        }

最佳答案

在MSDN网站上进行了更多阅读之后,我决定走另一条路。

我最终将其作为一项服务,因为它最终将需要成为一项服务,并执行以下操作:

 CookieContainer emersoncookie = new CookieContainer();

            HttpWebRequest request = (HttpWebRequest)
            WebRequest.Create("https://websiteaddress");

            request.Credentials = new NetworkCredential("username", "password");
            request.CookieContainer = emersoncookie;

            request.Method = "GET";
            HttpWebResponse response = (HttpWebResponse)
            request.GetResponse();

            Stream resStream = response.GetResponseStream();

            using (Stream output = File.OpenWrite(@"c:\\somefolder\\somefile.someextention"))
            using (Stream input = resStream)
            {
                input.CopyTo(output);
            }


对于可能遇到Siteminder身份验证问题的任何人,这段代码都可以很好地工作。

关于c# - C#Siteminder身份验证,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/29949870/

10-10 09:12