HTTPWebRequest using PUT method.

Sample for HTTPWebRequest using PUT Method.

try
{
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);
dataStream.Close();
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
string returnString = response.StatusCode.ToString();
}
catch {}

4 comments:

Unknown said...

this is good script, i need php script for same functionality that making put method call to API using php.

Anonymous said...

Simple, nice and concise. Shows what is needed to be done correctly.
Although a little explanation would be better.

Unknown said...

it will be better if u add how to send image data as byte array

Unknown said...

it will be better if u add how to send image data as byte array