错误的请求错误HttpClient

时间:2018-02-06 17:02:24

标签: c# asp.net wcf httpclient

我有以下实现。它确实有效。但是,当我重新启动wcf服务并再次按如下方式调用HTTPClient时,我收到错误的请求错误。

错误讯息:

StatusCode: 400,  
ReasonPhrase: 'Bad Request',  
Version: 1.1, 
Content: System.Net.Http.StreamContent, 
Headers: { cache-control: private transfer-encoding: chunked server: Microsoft-IIS/10.0 x-aspnet-version: 4.0.30319 x-sourcefiles:
=?UTF-8?B?QsrdfeterRk1cU2VydmVyXEFwcGxpY2F0aW9uIFNlcnZlclxGaWVsZCBSZXBvcnRlclxPcHNDZW50ZXIuTW9iaWxlLlN5bmNcTW9iaWxlRmllbGRTZXJ2aWNlLnN2Y1xEb3d511454eredefew==?= x-powered-by: ASP.NET date: Tue, 06 Feb 2018 16:54:43 GMT connection: close content-type: text/html }}

代码实施

private static T GoRequest<T>(string url, Dictionary<string, object> parameters, HttpMethod method, string body = "") where T : class
{
   using (var httpClient = new HttpClient(new HttpClientHandler()))
   {
     var request = new HttpRequestMessage(method, requestUri);
     if (body != string.Empty)
     {
        request.Content = new StringContent(body, Encoding.UTF8, "application/json");
     }

      try
      {
        using (var response = httpClient.SendAsync(request).Result)
        {
          Console.WriteLine(response);
        }
        catch (Exception ex)
        {
          Console.WriteLine(ex.Message);
        }
       }
    }
}

0 个答案:

没有答案
相关问题