HTTP/api/put APIを使用してデータ接続をOpenTSDBに配置しようとしています。 私はhttpclient、webRequest、およびHttpWebRequestを試しました。結果は常に400 - 不良要求:チャンク要求はサポートされていません。OpenTSDBを使用する.NETのHTTP api:400 Bad Request
私はapiテスター(DHC)でペイロードを試してもうまく動作しています。 私は非常に小さいペイロード( "x"のような普通の間違いでさえ)を送信しようとしましたが、返信は常に同じです。
は、ここに私のコードのインスタンスのいずれかです:私は明示的にfalse SendChunkedプロパティに設定
public async static Task PutAsync(DataPoint dataPoint)
{
try
{
HttpWebRequest http = (HttpWebRequest)WebRequest.Create("http://127.0.0.1:4242/api/put");
http.SendChunked = false;
http.Method = "POST";
http.ContentType = "application/json";
Encoding encoder = Encoding.UTF8;
byte[] data = encoder.GetBytes(dataPoint.ToJson() + Environment.NewLine);
http.Method = "POST";
http.ContentType = "application/json; charset=utf-8";
http.ContentLength = data.Length;
using (Stream stream = http.GetRequestStream())
{
stream.Write(data, 0, data.Length);
stream.Close();
}
WebResponse response = http.GetResponse();
var streamOutput = response.GetResponseStream();
StreamReader sr = new StreamReader(streamOutput);
string content = sr.ReadToEnd();
Console.WriteLine(content);
}
catch (WebException exc)
{
StreamReader reader = new StreamReader(exc.Response.GetResponseStream());
var content = reader.ReadToEnd();
}
return ;
}
。
ノートのような他の要求、その:完璧
public static async Task<bool> Connect(Uri uri)
{
HttpWebRequest http = (HttpWebRequest)WebRequest.Create("http://127.0.0.1:4242/api/version");
http.SendChunked = false;
http.Method = "GET";
// http.Headers.Clear();
//http.Headers.Add("Content-Type", "application/json");
http.ContentType = "application/json";
WebResponse response = http.GetResponse();
var stream = response.GetResponseStream();
StreamReader sr = new StreamReader(stream);
string content = sr.ReadToEnd();
Console.WriteLine(content);
return true;
}
作品。 私は本当に間違ったことをしていると確信しています。 私はソケットをゼロから再実装したいと思っています。