HOW to use the httpwebrequest object

zhaozj2021-02-12  145

This article was previously published under Q313126 SUMMARYThis article describes how to use the HttpWebRequest object and the HttpWebResponse object from the "System.Net" namespace to modify the urn: schemas: mailheader: subject property for an item in Microsoft Exchange 2000 Server in Microsoft Visual C # .NET MORE INFORMATIONTo modify the urn:. schemas: mailheader: subject property for an item in Visual C # .NET, follow these steps:. Start Microsoft Visual Studio .NET On the File menu, point to New, and then click Project. In The Visual C # Projects Types List, Click Console Application.

By Default, Class1.cs is created.in the code window, replace the code with the following: using system; using system.io;

Namespace WebDavnet {///

/// summary description for class1. /// class class1 {static void main (string [] args) {Try {// Todo: Replace with the url of an Object In Exchange Server String Suri = "http://exchserver/public/myfolder/test.eml";

System.uri myuri = new system.uri (suri); httpWebRequest httpwrequest = (httpwebrequest) WebRequest.create (Myuri);

String squery; squeery = "" " " " " " " ModifiedSubject " " " " "< / a: propertyupdate> "; // Set Credentials // TODO: Replace with appropriate user credential NetworkCredential myCred = new NetworkCredential (@" DomainName / UserName "," Password "); CredentialCache myCredentialCache = new CredentialCache (); myCredentialCache.Add ( myUri, "Basic", myCred); HttpWRequest.Credentials = myCredentialCache; // Uncomment the following statement and comment the previous 4 statements if you // use Integrated Windows authentication //httpWRequest.Credentials = CredentialCache.DefaultCredentials

// Note In Basic type authentication, the username and the password are sent as base64-encoded text, which is // easily decoded. Microsoft recommends that you use Basic over SSL to help protect the username and the password.

// set headers httpwrequest.keepalive = false; httpwrequest.headers.set ("Pragma", "no-cache"); httpwRequest.headers.set ("translate", "f"); httpwrequest.contenttype = "text / xml "HttpwRequest.contentLength = SQuery.Length;

// set the request timeout to 5 min HttpWRequest.Timeout = 300000;. // set the request method HttpWRequest.Method = "PROPPATCH"; // You must store the data in a byte array byte [] ByteQuery = System.Text. Encoding.ASCII.GetBytes (sQuery); HttpWRequest.ContentLength = ByteQuery.Length; Stream QueryStream = HttpWRequest.GetRequestStream (); // Write the data to be posted to the Request Stream QueryStream.Write (ByteQuery, 0, ByteQuery.Length) QueryStream.close ();

// Send Request and Get Response HttpWebResponse HttpWResponse = (HttpWebResponse) HttpWRequest.GetResponse (); // Get the Status code int iStatCode = (int) HttpWResponse.StatusCode; string sStatus = iStatCode.ToString (); Console.WriteLine ( "Status Code: {0} ", sstatus); // Get The Request Headers String Sreqheaders = httpWRequest.Headers.toT7tring (); console.writeline (Sreqheaders);

// Read the Response Stream Stream strm = HttpWResponse.GetResponseStream (); StreamReader sr = new StreamReader (strm); string sText = sr.ReadToEnd (); Console.WriteLine ( "Response: {0}", sText);

// Close stream strm.close ();

// Clean Up myCred = null; myCredentialCache = null; HttpWRequest = null; HttpWResponse = null; QueryStream = null; strm = null; sr = null;} catch (Exception e) {Console.WriteLine ( "{0} Exception caught. ", e);}}}} search for todo in the code, and then modify the code for your environment.build and then the subject of the specified item has been modified.

转载请注明原文地址:https://www.9cbs.com/read-6320.html

New Post(0)