REST呼叫响应HTTPS状态415

时间:2019-02-21 13:12:02

标签: json rest http-status-code-415

请在下面找到我的控制器代码。

[HKEY_CURRENT_USER\Software\Michael Herf\flux\Preferences]
"fullscreendisable"=dword:00000001

请求数据类:

@RequestMapping(value = "/reconrangesummary", method=RequestMethod.POST, produces=MediaType.APPLICATION_JSON_VALUE, consumes = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody
public String getReconRangeSummaryReport(@RequestBody RequestData requestData){
    logger.info("Inside Interest Service Controller - getReconRangeSummaryReport");
    List<ReconRangeSummaryDetails> reconRangeSummaryDetails = new ArrayList<ReconRangeSummaryDetails>();
    DashboardRequestDetails requestDetails = AccountUtils.convertRequest(requestData);
    reconRangeSummaryDetails = accountService.getReconRangeSummaryDetails(requestDetails);
    logger.info("Exit Interest Service Controller - getReconRangeSummaryReport");

    return new Gson().toJson(reconRangeSummaryDetails);

}

我正在使用 POST方法和content-type:application / json 在邮递员中传递以下请求。

public class RequestData {

private String role;
private String branchCode;
private String circle;
private String requestDate;
public String getRole() {
    return role;
}
public void setRole(String role) {
    this.role = role;
}
public String getBranchCode() {
    return branchCode;
}
public void setBranchCode(String branchCode) {
    this.branchCode = branchCode;
}
public String getCircle() {
    return circle;
}
public void setCircle(String circle) {
    this.circle = circle;
}
public String getRequestDate() {
    return requestDate;
}
public void setRequestDate(String requestDate) {
    this.requestDate = requestDate;
}

但是我收到如下错误响应。

HTTP状态415
服务器拒绝了此请求,因为请求实体的格式不受请求方法()的请求资源支持。

1 个答案:

答案 0 :(得分:0)

在发布请求时,在这种情况下,您还必须指定JSON / Application媒体类型。 如果您使用邮递员,请更改以下复选框:enter image description here

或如果需要的话,使用命令行版本:

curl -d '{"role":"makeruser", "branchCode":"00112", "circle":"circlename", "requestDate":"17-12-2018"}' -H "Content-Type: application/json" -X POST http://localhost:9009/new/reconrangesummary