使用C#调用POST请求调用。将PowerShell代码转换为CSharp代码
如何将这一行PowerShell代码转换为C#代码 调用RestMethod-方法Post-Uri“” 我正在使用VisualStudio来完成这项工作 请让我知道使用C#调用POST请求调用。将PowerShell代码转换为CSharp代码,c#,visual-studio,powershell,C#,Visual Studio,Powershell,如何将这一行PowerShell代码转换为C#代码 调用RestMethod-方法Post-Uri“” 我正在使用VisualStudio来完成这项工作 请让我知道 感谢使用HttpClient: // HttpClient is intended to be instantiated once per application, rather than per-use. See Remarks. static readonly HttpClient client = new HttpClient
感谢使用
HttpClient
:
// HttpClient is intended to be instantiated once per application, rather than per-use. See Remarks.
static readonly HttpClient client = new HttpClient();
static async Task Main()
{
// Call asynchronous network methods in a try/catch block to handle exceptions
try
{
HttpResponseMessage response = await client.PostAsync("https://s16events.azure-automation.net/webhooks?token=sdnfgknsdkfglkshnklsdfhgoihohsndfgndfgknkkdfg", new StringContent(requestBody));
response.EnsureSuccessStatusCode();
string responseBody = await response.Content.ReadAsStringAsync();
Console.WriteLine(responseBody);
}
catch(HttpRequestException e)
{
Console.WriteLine("\nException Caught!");
Console.WriteLine("Message :{0} ",e.Message);
}
}
改编自