gpt4 book ai didi

C# Siteminder 身份验证

转载 作者:太空宇宙 更新时间:2023-11-03 15:41:57 25 4
gpt4 key购买 nike

我正在尝试编写一些代码来连接到使用 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# Siteminder 身份验证,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29949870/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com