【发布时间】:2021-02-09 11:10:17
【问题描述】:
我有以下课程:
@CrossOrigin()
@PostMapping(path = "/xcpd", produces = "application/json; charset=utf-8")
protected String xcpd(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
JSONObject jsonData = null;
JSONObject jObj = new JSONObject();
JSONObject responseXCPD = null;
int user_id = -1;
int pid = -1;
try {
if ((jsonData = new JSONObject(getJSONString(request))) != null) {
if (jsonData.has("country_code") && jsonData.has("identifier")) {
// User data
user_id = Integer.valueOf(request.getParameter("user_id"));
String rolename = String.valueOf(request.getParameter("rolename"));
....
}
}
}
}
我正在使用以下 curl 调用来调用此端点:
curl -X POST -H "Content-Type: application/json" http://localhost:8083/xcpd -d '{"user_id":"1",
"country_code":"IE",
"rolename": "doctor",
"identifier": "1.1.1.1"
}'
当我调用 curl 示例时,我收到此行 user_id = Integer.valueOf(request.getParameter("user_id")); 的错误 java.lang.NumberFormatException: null。我想这意味着字符串user_id 是空的,不能转换成整数。
有什么帮助吗?
【问题讨论】:
标签: java curl http-post spring-tool-suite