我的代码是
import play.libs.ws.WSClient;
import play.libs.ws.WSResponse;
import play.libs.Json;
import play.libs.ws.WSRequest;
import play.mvc.BodyParser;
public class CouponsController extends Controller {
@BodyParser.Of(BodyParser.Json.class)
public CompletionStage<Result> test() {
WSRequest request = ws.url("http://jsonplaceholder.typicode.com/posts/1");
CompletionStage<WSResponse> responsePromise = request.get();
return responsePromise.thenApply(response-> ok(response.getBodyAsStream()));
}
}
我收到错误415不支持的媒体类型响应与上面的代码。我犯的错是什么?
和body包含错误
Bad Request
For request 'GET /coupons/test' [Expected application/json]
注意: 我删除了 @ BodyParser.Of(BodyParser.Json.class) 它工作了