12

How would i go about adding to the body of a HttpWebRequest?

The body needs to be made up of the following

<?xml version="1.0" encoding="utf-8"?>
<ChangeConfiguration xmlns="http://schemas.microsoft.com/windowsazure">
   <Configuration>base-64-encoded-configuration-file</Configuration>
   <TreatWarningsAsError>true|false</TreatWarningsAsError>
   <Mode>Auto|Manual</Mode>
</ChangeConfiguration>

Any help is much appreciated

StevenR
  • 435
  • 1
  • 6
  • 16

3 Answers3

27
byte[] buf = Encoding.UTF8.GetBytes(xml);

request.Method = "POST";
request.ContentType = "text/xml";
request.ContentLength = buf.Length;
request.GetRequestStream().Write(buf, 0, buf.Length);

var HttpWebResponse = (HttpWebResponse)request.GetResponse();
L.B
  • 114,136
  • 19
  • 178
  • 224
6

Don't know about Azure, but here just the general outline to send data with a HttpWebRequest :

string xml = "<someXml></someXml>";
var payload = UTF8Encoding.UTF8.GetBytes(xml);
HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://foo.com");
request.Method = "POST";
request.ContentLength = payload.Length;
using(var stream = request.GetRequestStream())
stream.Write(payload, 0, payload.Length);

If you don't need a HttpWebRequest for some reason, using a WebClient for uploading data is much more concise:

using (WebClient wc = new WebClient())
{
    var result = wc.UploadData("http://foo.com", payload);
}
BrokenGlass
  • 158,293
  • 28
  • 286
  • 335
-1

My book chapter showing how to use the Windows Azure Service Management API (and create the payload) can be downloaded for free.

Neil Mackenzie
  • 2,817
  • 14
  • 11