我正在使用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
?