安心を使用して休憩呼び出しを呼び出そうとしています。私の API は"application/json"
コンテンツ タイプとして受け入れ、呼び出しで設定する必要があります。以下のようにコンテンツタイプを設定しました。
オプション1
Response resp1 = given().log().all().header("Content-Type","application/json")
.body(inputPayLoad).when().post(addUserUrl);
System.out.println("Status code - " +resp1.getStatusCode());
オプション 2
Response resp1 = given().log().all().contentType("application/json")
.body(inputPayLoad).when().post(addUserUrl);
私が得る応答は「415」です(「サポートされていないメディアタイプ」を示します)。
プレーンな Java コードを使用して同じ API を呼び出してみましたが、動作します。なんらかの不思議な理由で、私は RA を介して動作させることができません。
HttpClient client = new DefaultHttpClient();
HttpPost post = new HttpPost(addUserUrl);
StringEntity input = new StringEntity(inputPayLoad);
input.setContentType("application/json");
post.setEntity(input);
HttpResponse response = client.execute(post);
System.out.println(response.getEntity().getContent());
/*
BufferedReader rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
String line = "";
while ((line = rd.readLine()) != null) {
System.out.println("Output -- " +line);
}