Recently, the partner used IIS as the file server.
The partner has configured the following information for us:
An http ulr, user name, and password. It tells us that you can upload files through HTTP.
We cannot operate the partner server because we only know that it is an IIS server;
I found a lot of data and spent a lot of time learning how to upload files through IIS.
After searching for a long time, I did not find a lot of relevant information. Finally, I saw an English article on Microsoft's website.ArticleAnd test it slowly. Finally, solve the problem.
The put/delete operation supported by http1.1 is mainly used. Usually, we only get or post ..
For more information, see:
IIS configuration server:
1. Create a new site in IIS (detailed operation skipped)
2. Right-click the site and choose Properties> Home Directory => hook "write"
3. In "iisweb service extension", "WebDAV" is allowed (I did not choose this option, but it won't work after testing for half a day)
4. In the site directory, configure everyone to be fully operational (for security purposes, you can only allow full control of a specific user; you can use this user to upload/delete it later)
Upload files in C:
CodeAs follows:
Public Void Uploadfilebinary ( String Localfile, String Uploadurl)
{
Httpwebrequest req = (Httpwebrequest) webrequest. Create (uploadurl );
Req. Credentials = New Networkcredential ( " Administrator " , 123456 " ); // User name and password
Req. preauthenticate = True ;
Req. Method = " Put " ;
Req. allowwritestreambuffering = True ;
// Retrieve request stream
Stream reqstream = Req. getrequeststream ();
// Open the local file
Filestream RDR = New Filestream (localfile, filemode. Open );
// Allocate byte buffer to hold File Contents
Byte [] Indata = New Byte [ 4096 ];
// Loop through the local file reading each data block
// And writing to the request Stream Buffer
Int Bytesread = RDR. Read (indata, 0 , Indata. Length );
While (Bytesread > 0 )
{
Reqstream. Write (indata,0, Bytesread );
Bytesread=RDR. Read (indata,0, Indata. Length );
}
RDR. Close ();
Reqstream. Close ();
Req. getresponse ();
}
Code for deleting an object:
Public Void Deletefile ( String Uploadurl)
{
Httpwebrequest req = (Httpwebrequest) webrequest. Create (uploadurl );
Req. Credentials = New Networkcredential ( " Administrator " , " 123456 " );
Req. preauthenticate = True ;
Req. Method = " Delete " ;
// Req. allowwritestreambuffering = true;
Req. getresponse ();
}