嗯,您不会直接拨打cURL,而是使用以下选项之一:
我强烈建议使用HttpClient
类,因为它的设计(从可用性的Angular )比前两个好得多.
在您的情况下,您可以这样做:
using System.Net.Http;
var client = new HttpClient();
// Create the HttpContent for the form to be posted.
var requestContent = new FormUrlEncodedContent(new [] {
new KeyValuePair<string, string>("text", "This is a block of text"),
});
// Get the response.
HttpResponseMessage response = await client.PostAsync(
"http://api.repustate.com/v2/demokey/score.json",
requestContent);
// Get the response content.
HttpContent responseContent = response.Content;
// Get the stream of the content.
using (var reader = new StreamReader(await responseContent.ReadAsStreamAsync()))
{
// Write the output.
Console.WriteLine(await reader.ReadToEndAsync());
}
还请注意,与前面提到的选项相比,HttpClient
类更好地支持处理不同的响应类型,并且更好地支持异步操作(以及它们的取消).