2015-10-11 35 views
0

我想提出一個請求,我的REST服務爲:得到休息服務做成一個字符串請求

捲曲-H「內容類型:應用程序/ JSON」 -X POST -d「{‘ID’ :4,「name」:「xyz」}'http://localhost:8080/SpringMVC/operation/creation

我想在Controller類中以字符串形式訪問這個請求。

@RequestMapping(value = "/creation", method = RequestMethod.POST, consumes = "application/json") 
public @ResponseBody ResponseEntity<String> posting(@RequestBody ModelClass modelClass) { 

    // Code here 

} 

有什麼辦法,我可以得到:

字符串請求= 捲曲-H 「內容類型:應用程序/ JSON」 -X POST -d「{ 「ID」:4,「名稱「:」xyz「}'http://localhost:8080/SpringMVC/operation/creation

或者至少端點作爲我的控制器類中的字符串?

+0

'String request',String value should be closed in double quotes。 – YoungHobbit

回答

0

您可以將HttpServletRequest作爲參數添加到方法中。然後您可以從請求對象獲取RequestRequestURI或getRequestURL。

 
public @ResponseBody ResponseEntity posting(@RequestBody ModelClass modelClass, HttpServletRequest request) { 
    request.getRequestURI(); // gets the path component of the request 
    request.getRequestURL(); // gets the complete request url 
}