Recently, the vsto program needs to upload documents to the moss platform. Because the website uses windows integrated authentication, you must enter a password for permission issues. This makes operations and user experience very inconvenient. After studying for a long time, I did not find a good method. Finally, I finally summed up the following methods for breaking the tie shoes, my personal understanding of the principle is to simulate IE to send verification messages for verification, you can achieve the login problem.
Note: You need to add COM references named Microsoft XML and V2.6 or later versions.
Copy codeThe Code is as follows: private void button3_Click (object sender, EventArgs e)
{
This. textBox1.Text = @ "http: // localhost/Default. aspx"; // The authenticated URL or path
This. textBox2.Text = "spsservice"; // account name
This. textBox3.Text = "Zd $1234"; // Password
MSXML2.XMLHTTP http = new MSXML2.XMLHTTP ();
Http. open ("post", this. textBox1.Text, false, this. textBox2.Text, this. textBox3.Text );
Http. send ("");
Switch (http. status)
{
Case 200:
{
MessageBox. Show ("Logon successful! ");
Break;
}
Case 401:
{
MessageBox. Show ("incorrect user name and password ");
Break;
}
Default:
{
MessageBox. Show ("connection failed, please try again ");
Break;
}