我有一个在 Spring SVM 上运行的 web 应用程序,它朝这个方向运行:
http://localhost:8085/mongodb
处理 GET 和 POST 请求的主控制器如下所示:
@Controller
public class HomeController {
private static final Logger logger = LoggerFactory.getLogger(HomeController.class);
private static final String DATA_FIELD = "Data";
@RequestMapping(value = "/", method = RequestMethod.GET)
public String home(Model model) {
return "home";
}
@RequestMapping(value = "/", method = RequestMethod.POST)
public ModelAndView createDomain(@RequestBody Domain Domain, HttpServletResponse httpresponse, WebRequest request) throws Exception{
logger.info("Welcome home! The client locale is {}.", "FUCK YOU2");
Domain createdDomain = Domain;
logger.info("Post Received" + Domain.toString());
//Create HTTP Response for the POST request
httpresponse.setStatus(HttpStatus.CREATED.value());
MongoOperations mongoOps = new MongoTemplate(new Mongo(),"rest_database");
mongoOps.insert(Domain);
System.out.println("PRINTED");
return new ModelAndView("post", DATA_FIELD, createdDomain);
}
}
显然代码正在运行。当我使用 Chrome 扩展高级 Rest 客户端(此处)发送 POST 请求时,客户端每次发送一个 POST 然后一个 GET,所以我总是在 GET 方法中获取页面。
奇怪的是,谷歌浏览器网络开发工具显示一个 POST 请求挂起,然后一个返回 OK 的 GET 请求,网络调试器显示:
https://dl.dropboxusercontent.com/u/7437425/network_debugger.png
当我发送此请求时:
https://dl.dropboxusercontent.com/u/7437425/post_response.png
我想知道这是否是发送 POST 的标准方式,不久之后发送 GET。
A funny thing is that my console never shows the result of this commands:
logger.info("Welcome home! The client locale is {}.", "FUCK YOU2");
System.out.println("PRINTED");
This leads me to believe that actually the method that handle POST requests is not running at all.
Thanks!