我需要访问中央身份验证服务器后面的 php 页面。使用任何其他方式,当我尝试访问此站点时,它会重定向到 CAS 页面,等待身份验证。从本质上讲,让我向GET
身份验证页面提供变量。(不想要。)不幸的是,我们无法删除此页面的 CAS,因为它存在巨大的安全风险。
所以我的问题是,是否有向 CAS 提供我所拥有的凭据,从中存储任何 cookie,然后使用它,访问 php 页面?
我的尝试如下:
由于我正在使用该GET
方法,我无需担心等到我在 php 页面提供值,我只需要实际访问该页面,我们将调用它https://site.com/page.php?var1=value1&var2=value2
由于WebClient 使用建议的凭据访问页面,我创建了一个类CookieAwareClient
public class CookieAwareWebClient : WebClient
{
public CookieAwareWebClient()
{
CookieContainer = new CookieContainer();
}
public CookieContainer CookieContainer { get; private set; }
protected override WebRequest GetWebRequest(Uri address)
{
var request = (HttpWebRequest)base.GetWebRequest(address);
request.CookieContainer = CookieContainer;
return request;
}
}
然后提交以下内容:
使用 (var client = new CookieAwareWebClient())
using (var client = new CookieAwareWebClient())
{
var values = new NameValueCollection
{
{"username", "usr" },
{"password", "(passw0rd!)"}, //don't worry. not actual information
};
//This should bring me to the login page, which will upload the values I have given
client.UploadValues("https://site.com/page.php?var1=value1&var2=value2", values);
string result = client.DownloadString("https://site.com/page.php?var1=value1&var2=value2");
不幸的是,这仍然没有让我登录到 CAS,结果作为 CAS 的 HTML 返回。
有谁知道我如何解决这个问题?感谢您的帮助。