【发布时间】:2020-07-27 17:40:08
【问题描述】:
在使用这个 GET 端点时遇到了一些问题。由于某种原因,调用状态 500 Internal Server Error 并且正文为空。
这是带有 GET 调用的代码:
@GetMapping
public List<TitulosPagar> getTitulosPagar() {
System.out.println("GET called");
List<TitulosPagar> titulos = titulosPagarService.pesquisar();
System.out.println(titulos);
return titulos;
titulosPagarService.pesquisar() 返回一个 JpaRepository.findAll() 以及完整的 titulosPagar 列表。
sysoutPrint 显示它获取了由 TitulosPagar 对象组成的列表:
GET called
[br.com.lev.ficpagar.model.TitulosPagar@13d10944, br.com.lev.ficpagar.model.TitulosPagar@5a57aa65,
br.com.lev.ficpagar.model.TitulosPagar@1ac0f72, br.com.lev.ficpagar.model.TitulosPagar@3a052abc]
但在 Postman 中,我得到了一个空正文和 500 内部服务器错误
邮递员控制台响应:
GET /ficpagar/titulospagar HTTP/1.1
Content-Type: application/json
User-Agent: PostmanRuntime/7.24.1
Accept: */*
Cache-Control: no-cache
Postman-Token: b273167d-92d4-44e6-bea0-88c8b70af99e
Host: localhost:8080
Accept-Encoding: gzip, deflate, be
Connection: keep-alive
HTTP/1.1 500 Internal Server Error
Access-Control-Allow-Origin: http://localhost:4200
Access-Control-Allow-Credentials: true
Content-Type: application/json
Transfer-Encoding: chunked
Date: Tue, 14 Apr 2020 20:31:03 GMT
Connection: close
,
curl --location --request GET 'localhost:8080/ficpagar/titulospagar' \
--header 'Content-Type: application/json' \
--data-raw ''
奇怪的是,这个测试 GET 端点运行良好。
@GetMapping
public String test() {
return "Everything fine!";
}
还有 POST 端点:
@PostMapping
public ResponseEntity<TitulosPagar> criar(@Valid @RequestBody TitulosPagar tituloPagar, HttpServletResponse response) {
tituloPagar = titulosPagarService.criar(tituloPagar);
URI uri = ServletUriComponentsBuilder.fromCurrentRequestUri().path("/{codigo}").buildAndExpand(tituloPagar.getId()).toUri();
response.setHeader("Location", uri.toASCIIString());
return ResponseEntity.created(uri).body(tituloPagar);
}
我在 PostgreSQL 中使用 localServer。
它不知道t seem to be a problem in the code. But I dont 知道,你明白可能出了什么问题吗?
【问题讨论】:
-
请分享您邮递员的 curl 请求
标签: javascript java postgresql postman restful-authentication