如何登录窗口授权 [英] How to login window authorisation
问题描述
我有来自我的本地网站的HMTL代码我正在使用此代码
// 我们将使用WebClient类来读取网页的HTML
WebClient MyWebClient = new WebClient();
// 读取网页HTML到字节数组
< span class =code-sdkkeyword> Byte [] PageHTMLBytes;
if (textBox1.Text!= )
{
PageHTMLBytes = MyWebClient.DownloadData(textBox1.Text);
// 将结果从字节数组转换为字符串
< span class =code-comment> // 并在TextBox中显示txtPageHTML
UTF8Encoding oUTF8 = new UTF8Encoding();
richTextBox1.Text = oUTF8.GetString(PageHTMLBytes);
}
buut这个网站首先需要Windows Authoristation我知道用户和密码buuut我怎么能用表单授权它是错误的mee unauthorise beaocuse我不输入任何用户和密码我需要这个表格,将密码字段中的密码和用户字段中的用户帮助人员
如果目标页面使用Windows身份验证,则很容易:
// 我们将使用WebClient类来阅读网页的HTML
WebClient MyWebClient = new WebClient();
MyWebClient.Credentials = new NetworkCredential( myusername, mypassword);
// 读取网页HTML到字节数组
< span class =code-sdkkeyword> Byte [] PageHTMLBytes;
...
这会将Windows凭据添加到身份验证标题中。
如果使用其他身份验证机制,则需要以不同方式提供凭据。表格认证的一个很好的例子可以在以下网址找到:
c# - WebClient访问带有凭据的页面 - Stack Overflow [ ^ ]
I have probelem guys i am taking HMTL code from my local Site i am using this code
// We'll use WebClient class for reading HTML of web page
WebClient MyWebClient = new WebClient();
// Read web page HTML to byte array
Byte[] PageHTMLBytes;
if (textBox1.Text != "")
{
PageHTMLBytes = MyWebClient.DownloadData(textBox1.Text);
// Convert result from byte array to string
// and display it in TextBox txtPageHTML
UTF8Encoding oUTF8 = new UTF8Encoding();
richTextBox1.Text = oUTF8.GetString(PageHTMLBytes);
}
buut this site first need Windows Authoristation i know User and password buuut how can i authorise with form it is erroring mee unauthorise beaocuse i don't enter any user and password i need that form that will take this password in password field and user in user field Help guys
If the target page is using Windows authentication it's easy:
// We'll use WebClient class for reading HTML of web page WebClient MyWebClient = new WebClient(); MyWebClient.Credentials = new NetworkCredential("myusername","mypassword"); // Read web page HTML to byte array Byte[] PageHTMLBytes; ...
This will add the windows credentials into the authentication header.
If a different authentication mechanism is being used, you will need to provide the credentials in a different way. A really good example for forms authentication can be found at:
c# - WebClient accessing page with credentials - Stack Overflow[^]
这篇关于如何登录窗口授权的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!