私はPOSTメソッドのリクエストボディに "/" 文字を送った際に不正な要求を取得取得HTTP/1.1 400不正な要求[ r]を[ nを]
HttpClient client = new HttpClient();
PostMethod postMethod = new PostMethod(kairosDBUrl);
RequestEntity requestEntity = null;
try {
requestEntity = new StringRequestEntity(inputBody, "text/json", "UTF-8");
postMethod.setRequestEntity(requestEntity);
client.executeMethod(postMethod);
responseBody = IOUtils.toString(postMethod.getResponseBodyAsStream(), postMethod.getResponseCharSet());
} catch (IOException e) {
LOG.error("Unexpected exception : {}", e);
} finally{
postMethod.releaseConnection();
}
入力:
{metrics=[{name=apache.Activity_Bytes/req, tags={host=[ip-10-0-0-201]}, aggregators=[{name=avg, align_sampling=true, sampling={value=5, unit=seconds}}]}], cache_time=0, start_absolute=1496222264000, end_absolute=1496224064000}
エラー:
"{"errors":["com.google.gson.stream.MalformedJsonException: Unterminated object at line 1 column 39"]}"
これは単なる野生の推測ですが、スラッシュをその前にバックスラッシュでエスケープしようとしましたか? – Jonathan
JSONが無効です。修正する必要があります。 – Dorian
JSONは完全にうんざりです。あなたの入力を修正するにはhttp://json-validator.com/を試してください。 –