Put the data into your http

We can put the data into our http using the following code

Namespaces


using System;
using System.IO;
using System.Net;



public class MyHTTPPut {

public static void Main(string [] args) {

string Myurl = "http://www.Dotnetspider.com/";
string Myusername = "My user id";
string Mypassword = "My password";
string Mydata = "My Data ";

HttpWebRequest MyRequest = (HttpWebRequest)WebRequest.Create(Myurl);
MyRequest.Method = "PUT";
MyRequest.Credentials = new NetworkCredential(Myusername, Mypassword);
MyRequest.ContentLength = data.Length;
MyRequest.ContentType = "text/plain";

using (StreamWriter writer = new StreamWriter(Myrequest.GetRequestStream( ))) {
writer.WriteLine(Mydata);
}

WebResponse Myresponse = Myrequest.GetResponse( );

using (StreamReader Myreader = new StreamReader(Myresponse.GetResponseStream( ))) {
while (Myreader.Peek( ) != -1) {
Console.WriteLine(Myreader.ReadLine( ));
}
}
}
}


Code Explanation

1. Create the instance of HttpWebRequest
2. Assign the method "PUT"
3. Write the data
4. The data should be written to the URL.

By
Nathan


Comments

No responses found. Be the first to comment...


  • Do not include your name, "with regards" etc in the comment. Write detailed comment, relevant to the topic.
  • No HTML formatting and links to other web sites are allowed.
  • This is a strictly moderated site. Absolutely no spam allowed.
  • Name:
    Email: