英文:
Getting null pointer exception on more than one request parameter in curl GET request
问题
1, 单个请求参数的Curl命令:
curl --insecure -X GET "Content-Type:application/json" https://localhost/test?pageSize=1
正常运行。
2, 多个请求参数的Curl命令:
curl --insecure -X GET "Content-Type:application/json" https://localhost/test?pageSize=1&pageNumber=0
我得到pageNumber是null,抛出空指针异常。
示例Java控制器类
@Controller
@RequestMapping("/api/test")
public class TestController {
@RequestMapping(method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<Object> getTest(
@RequestParam(value = "pageSize", required = false) Integer pageSize,
@RequestParam(value = "pageNumber", required = false) Integer pageNumber,
HttpServletRequest hsrequest, HttpServletResponse hsresponse) {
// 实现部分
}
英文:
1, Curl command for single request parameter:
curl --insecure -X GET "Content-Type:application/json" https://localhost/test?pageSize=1
Working fine.
2, Curl command for mulitple request parameters:
curl --insecure -X GET "Content-Type:application/json" https://localhost/test?pageSize=1&pageNumber=0
I'm getting pageNumber is null, throwing null pointer exception
Sample Java controller class
@Controller
@RequestMapping("/api/test")
public class TestController {
@RequestMapping(method = RequestMethod.GET, producesMediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<Object> getTest(
@RequestParam(value = "pageSize", required = false) Integer pageSize,
@RequestParam(value = "pageNumber", required = false) Integer pageNumbe,
HttpServletRequest hsrequest, HttpServletResponse hsresponse) {
//implementation
}
答案1
得分: -1
curl --insecure -X GET "Content-Type:application/json" "https://localhost/test?pageSize=1&pageNumber=0"
英文:
2, Curl command for mulitple request parameters:
curl --insecure -X GET "Content-Type:application/json" https://localhost/test?pageSize=1&pageNumber=0
Solution: Added quotes to URL
curl --insecure -X GET "Content-Type:application/json" "https://localhost/test?pageSize=1&pageNumber=0"
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论