简体   繁体   English

如何将JSON数据发布到.net的请求正文中?

[英]How can I post JSON data to the body of a request from .net?

How can I post JSON data to the body of a request from .net? 如何将JSON数据发布到.net的请求正文中?

I am using .net 2010 and apparently thr httpclient is not available to me. 我正在使用.net 2010,显然我无法使用httpclient。 I converted data to JSON and now need to post it to a Ruby api and they want it in the body. 我将数据转换为JSON,现在需要将其发布到Ruby API中,他们希望将其保存在正文中。

If you are not using any specific libraries, you should be able to use System.Net.WebClient . 如果您没有使用任何特定的库,则应该可以使用System.Net.WebClient Here's an example: 这是一个例子:

var wc = new WebClient();
wc.Headers.Add("Content-Type", "application/json; charset=utf-8");
var result = wc.UploadString("http://your/api/url", "POST", your_json_string);

assuming that your_json_string is a string variable which holds you data in JSON format. 假设your_json_string是一个string变量,可以将您的数据保存为JSON格式。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM