【问题标题】:Bad request during POST request to influxDB from asp.net从 asp.net 到 influxDB 的 POST 请求期间出现错误请求
【发布时间】:2017-09-14 23:16:42
【问题描述】:

我正在尝试向我的本地 influxDB 发送 POST 请求。 我收到 StatusCode: 400, ReasonPhrase: 'Bad Request'"

 HttpClient client = new HttpClient();
 HttpRequestMessage requestMessage = new HttpRequestMessage(HttpMethod.Post, "http://localhost:8086/write?db=mydb");
 requestMessage.Content = new StringContent("cpu_load_short, host = server01, region = us - 345345 value = 0.34564 345345");
 HttpResponseMessage response = client.SendAsync(requestMessage).GetAwaiter().GetResult();

在我的 Postman 中,我将“http://localhost:8086/write?db=mydb”和“cpu_load_short,host=server01,region=us-345345 value=0.34564 345345”放在我的正文中(原始),它可以工作

【问题讨论】:

    标签: c# asp.net asp.net-mvc post influxdb


    【解决方案1】:

    尝试将内容类型设置为类似

    request.ContentType = "application/x-www-form-urlencoded"; 
    

    或者如果您也知道并确定编码类型,请使用此

    requestMessage.Content = new StringContent("cpu_load_short, host = server01, region = us - 345345 value = 0.34564 345345", Encoding.UTF8, "application/x-www-form-urlencoded"); // or whatever is the encoding type
    

    ContentType 属性包含请求的媒体类型

    【讨论】:

      猜你喜欢
      • 2019-07-17
      • 1970-01-01
      • 2017-06-29
      • 2017-04-15
      • 2019-04-20
      • 2021-12-21
      • 2016-08-25
      • 2021-11-22
      • 2017-01-22
      相关资源
      最近更新 更多