Home > Uncategorized > PUT Request with HttpWebRequest

PUT Request with HttpWebRequest

string str = “test”;
System.Text.ASCIIEncoding encoding = new System.Text.ASCIIEncoding();
byte[] arr = encoding.GetBytes(str);
HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(“url”);
request.Method = “PUT”;
request.ContentType = “text/plain”;
request.ContentLength = arr.Length;
request.KeepAlive = true;
Stream dataStream = request.GetRequestStream();
dataStream.Write(arr, 0, arr.Length);
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
string returnString = response.StatusCode.ToString();
catch {}

Credit to S.Vinothkumar for this code

Categories: Uncategorized
  1. Amit
    April 24, 2019 at 5:33 pm

    This’s an excellent peace of example. Worked PUT method perfectly after a long Googling. Thanks!


  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: