将 XML 对象附加到 asp.net REST 入门工具包中的 REST POST

发布于 2024-08-25 20:43:30 字数 638 浏览 8 评论 0原文

我第一次在 asp.net 中使用 REST 入门工具包,遇到了一些麻烦。

我创建了一些 XML...

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

然后创建了一个 httpClient...

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

现在我需要使用 http.POST() 将 xml 发布到正确的 URL。我认为我需要的重载方法是(string url, httpContent body)。所以我猜谜题中缺少的部分是如何将 xml 转换为 httpContent,我似乎无法实例化它。

有什么想法吗?

乔恩

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

断桥再见 2024-09-01 20:43:30

如果您真的从字符串开始,最简单的方法是

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

另一种方法是使用 XElement

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

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>"));
香橙ぽ 2024-09-01 20:43:30

抱歉,刚刚找到答案 -

HttpContent content = HttpContentExtensions.CreateXmlSerializable(newOrganizationXml);

Sorry, just found the answer -

HttpContent content = HttpContentExtensions.CreateXmlSerializable(newOrganizationXml);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文