当我调用 Spring Rest api 时,Postman 的 GET 请求不起作用
当我使用 GET 方法点击curl localhost:3306/api/v1/requests 从 mysql 数据库获取数据时,邮递员抛出该错误。
获取http://localhost:3306/api/v1/requests 错误:解析错误:预期的 HTTP/ 请求标头 用户代理:PostmanRuntime/7.29.0 接受:/ 邮递员令牌:867bb528-b3d6-410f-8c03-609ed49f3e90 主机:本地主机:3306 接受编码:gzip、deflate、br 连接:保持活动状态
这是控制器类的代码 @Autowired 私有RequestService rService;
//localhost:3306/request
@GetMapping("/requests")
public List<Request> getRequests(){
return rService.getRequests();
}
这是 RequestService 类的代码
public interface RequestService {
List<Request> getRequests();
}
这是 RequestServiceImpl 的代码
@Service
public class RequestServiceImpl implements RequestService{
@Autowired
private RequestRepository requestRepository;
@Override
public List<Request> getRequests() {
return requestRepository.findAll();
}
}
When i hit the curl localhost:3306/api/v1/requests with GET method to fetch the data from mysql database , postman throws that error.
GET http://localhost:3306/api/v1/requests
Error: Parse Error: Expected HTTP/
Request Headers
User-Agent: PostmanRuntime/7.29.0
Accept: /
Postman-Token: 867bb528-b3d6-410f-8c03-609ed49f3e90
Host: localhost:3306
Accept-Encoding: gzip, deflate, br
Connection: keep-alive
Here is code from controller class
@Autowired
private RequestService rService;
//localhost:3306/request
@GetMapping("/requests")
public List<Request> getRequests(){
return rService.getRequests();
}
Here is the code RequestService class
public interface RequestService {
List<Request> getRequests();
}
Here is code from RequestServiceImpl
@Service
public class RequestServiceImpl implements RequestService{
@Autowired
private RequestRepository requestRepository;
@Override
public List<Request> getRequests() {
return requestRepository.findAll();
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论