代码之家  ›  专栏  ›  技术社区  ›  TDeoodfig

从asp向influxDB发出POST请求期间的请求错误。网

  •  0
  • TDeoodfig  · 技术社区  · 7 年前

    我正试图向我当地的移民局发送POST请求。

     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();
    

    在我的邮递员中,我写下“ http://localhost:8086/write?db=mydb “和”cpu\u load\u short,host=server01,region=us-345345 value=0.34564 345“在我的身体(原始)中,它可以工作

    1 回复  |  直到 7 年前
        1
  •  2
  •   Jaya    7 年前

    尝试将内容类型设置为

    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