Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/300.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用C#调用POST请求调用。将PowerShell代码转换为CSharp代码_C#_Visual Studio_Powershell - Fatal编程技术网

使用C#调用POST请求调用。将PowerShell代码转换为CSharp代码

使用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

如何将这一行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();

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);
  }
}
改编自