休息服务器:
@RequestMapping(value = "/rest/{code}", method=RequestMethod.POST)
public @ResponseBody String sendMessage(@PathVariable String code) {
boolean h = true;
try {
String trackNum = code.substring(0, 34).trim();
String eventTime = code.substring(35, 60).trim();
String userName = code.substring(61, 70).trim();
String eventDispoCode = code.substring(71, 73).trim();
String loc = code.substring(73, 82).trim();
String eventTxt = code.substring(83);
History histInfo = new History();
histInfo.setDeviceName(userName+"_WEB");
histInfo.setLogInId(userName);
histInfo.setAppVersion("1");
histInfo.setLocCode(loc);
histInfo.setUserName(userName);
h = interceptService.processPackageIntercept(histInfo,loc, trackNum, new LocalDateTime(eventTime));
} catch (Exception e) {
e.printStackTrace();
}
if(h){
return "true";
}else{
return "false";
}
}
在服务器h = interceptService.processPackageIntercept(histInfo,loc, trackNum, new LocalDateTime(eventTime));
中,此服务具有将详细信息保存到数据库的方法。
休息客户端:
String url = "http://localhost:8090/packageintercept/rest/";
String st = (String) restTemplate.postForObject(url, b.toString(), String.class);
当我使用时,getForObject()
我可以点击 DB 来检索数据,但无法将其保存在那里。当我改为postForObject()
我得到HttpClientErrorException. 403 Forbidden error
有什么建议么!我在这里做错了什么?