POST 从 asp.net 向 influxDB 请求期间的错误请求
Bad request during POST request to influxDB from asp.net
我正在尝试向我的本地 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" 放入我的 body(raw) 中并且有效
尝试将内容类型设置为
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
属性包含请求的媒体类型
我正在尝试向我的本地 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" 放入我的 body(raw) 中并且有效
尝试将内容类型设置为
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
属性包含请求的媒体类型