如何在HttpGet请求中添加路径变量

时间:2018-02-09 14:59:15

标签: java spring httpclient apache-httpclient-4.x

我正在使用Spring,我可以直接获取客户端的路径变量,如下所示:

@Override
@ResponseBody
@RequestMapping(value = "/users/{username}/projects", method = GET)
public void projects(HttpServletRequest request, 
HttpServletResponse response, @PathVariable("username") String username, 
@RequestParam(value="position", required=false) Integer position) {

  System.out.println("Got username: "+username);
}

现在我想使用apache HttpClient获取相同的路径变量值,如下所示:

String projectsUrl = base_url + "userApi/users/{username}/projects?position="+position;
HttpGet getProjects = new HttpGet(projectsUrl);

显然这不起作用,因为缺少路径变量username。那么如何使用HttpClient获取此username

0 个答案:

没有答案