我从 android 客户端获取多部分消息。我正在使用 jersey webservice 来接收该多部分数据。我可以检索多部分数据。但我无法使用@Context HttpServletRequest
请求来获取用户 ID。我的安卓客户端是,
HttpClient httpClient = new DefaultHttpClient();
Log.e("Picture Upload URL is:", QueryConfig.PROTOCOL+ StaticHelper.HOST + StaticHelper.port+QueryConfig.projectService+QueryConfig.sendProfilePicture);
HttpPost postRequest = new HttpPost(QueryConfig.PROTOCOL+ StaticHelper.HOST + StaticHelper.port+QueryConfig.projectService+QueryConfig.sendProfilePicture);
ByteArrayBody bab = new ByteArrayBody(data,StaticHelper.UserID+".jpg");
MultipartEntity reqEntity = new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE);
reqEntity.addPart("file", bab);
reqEntity.addPart("fileFilename",new StringBody(StaticHelper.UserID+".jpg"));
HttpResponse response = httpClient.execute(postRequest);
我的球衣服务是
@Path("/mobileUserPictureInsert")
@POST
@Consumes("multipart/*")
@Produces(MediaType.APPLICATION_JSON)
public String save(@Context HttpServletRequest request, MultiPart multiPart)
throws ParseException {
BodyPartEntity bpeTokenId = (BodyPartEntity) multiPart.getBodyParts()
.get(2).getEntity();
try {
tokenId = getString(bpeTokenId.getInputStream());
String userId = "";
userId = getSession(tokenId, request);
获取会话方法是
protected String getSession(String token, HttpServletRequest req)
throws ServletException, IOException {
String value = (String) context.getAttribute(token);
LOG.info("Retrive Token Value-->" + value);
return value;
}
在这里,我传递了为检索用户 ID 而生成的请求和令牌。它适用于 get 方法。但对于 post 方法,我得到空值。请帮助我。如何在球衣中获取 post 方法的请求。