相关疑难解决方法(0)

如何在Spring RestTemplate请求上设置"Accept:"标头?

我想设置Accept:我使用Spring的请求中的值RestTemplate.

这是我的Spring请求处理代码

@RequestMapping(
    value= "/uom_matrix_save_or_edit", 
    method = RequestMethod.POST,
    produces="application/json"
)
public @ResponseBody ModelMap uomMatrixSaveOrEdit(
    ModelMap model,
    @RequestParam("parentId") String parentId
){
    model.addAttribute("attributeValues",parentId);
    return model;
}
Run Code Online (Sandbox Code Playgroud)

这是我的Java REST客户端:

public void post(){
    MultiValueMap<String, String> params = new LinkedMultiValueMap<String, String>();
    params.add("parentId", "parentId");
    String result = rest.postForObject( url, params, String.class) ;
    System.out.println(result);
}
Run Code Online (Sandbox Code Playgroud)

这适合我; 我从服务器端获得了一个JSON字符串.

我的问题是:当我使用RestTemplate时,如何指定Accept:标题(例如application/json,application/xml...)和请求方法(例如,...)?GETPOST

rest spring resttemplate

173
推荐指数
6
解决办法
30万
查看次数

标签 统计

rest ×1

resttemplate ×1

spring ×1