Here’s a C# example using HttpWebRequest:
using System;
using System.IO;
using System.Net;
class Test
{
static void Main()
{
string xml = "<xml>...</xml>";
byte[] arr = System.Text.Encoding.UTF8.GetBytes(xml);
HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create("http://localhost/");
request.Method = "PUT";
request.ContentType = "text/xml";
request.ContentLength = arr.Length;
Stream dataStream = request.GetRequestStream();
dataStream.Write(arr, 0, arr.Length);
dataStream.Close();
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
string returnString = response.StatusCode.ToString();
Console.WriteLine(returnString);
}
}
Update: there’s now an HttpClient class in System.Net.Http (available as a NuGet package) that makes this a bit easier:
using System;
using System.Net.Http;
class Program
{
static void Main()
{
var client = new HttpClient();
var content = new StringContent("<xml>...</xml>");
var response = client.PutAsync("http://localhost/", content).Result;
Console.WriteLine(response.StatusCode);
}
}