views:

197

answers:

2

Hi,

I'm using the REST starter kit in asp.net for the first time and having a bit of trouble.

I've created some XML...

String newOrganizationStrin = "<somexml></somexml>";
XmlDocument newOrganizationXml = new XmlDocument();
newOrganizationXml.LoadXml(newOrganizationString);

Then I create an httpClient...

HttpClient http = new HttpClient("https://companyname.capsulecrm.com/api/");
http.TransportSettings.Credentials = new NetworkCredential("APIKEY", "PASSWORD");

Now I need to use http.POST() to post the xml to the correct URL. The overloaded method I need I think is (string url, httpContent body). So I guess the missing piece of the puzzle is how to convert the xml to an httpContent, which I can't seem to instantiate.

Any ideas?

Jon

A: 

Sorry, just found the answer -

HttpContent content = HttpContentExtensions.CreateXmlSerializable(newOrganizationXml);
jonhobbs
A: 

If you are really starting with a string, the easiest way is

var content = HttpContent.Create("<somexml></somexml>","application/xml");

The other way is to use XElement

var content = HttpContentExtensions.Create(XElement.Parse("<somexml></somexml>"));
Darrel Miller