2017-09-14 156 views
0

我试图向我的本地influxDB发送POST请求。 我得到的StatusCode:400,ReasonPhrase: '坏请求'”在从asp.net向influxDB发送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_load_short,主机= SERVER01,区域= US-345345值= 0.34564 345345” 在我的身体(RAW)和它的作品

回答

2

尝试设置内容类型为类似

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属性包含请求的媒体类型