/** * 发上服务器的文件 * * @param file * @return */ private String sendHttpRequest(File file) { String string = null; PostMethod filePost = new PostMethod(targetURL); try { Part[] parts = { new FilePart("userFile.file", targetFile), new StringPart(paramType, param, "utf-8") }; HttpMethodParams params = filePost.getParams(); params.setContentCharset("utf-8"); filePost.setRequestEntity(new MultipartRequestEntity(parts, filePost.getParams())); httpClient.getHttpConnectionManager().getParams().setConnectionTimeout(50000); Log.v("filePost", filePost.toString()); Log.v("param", param); Log.v("paramType", paramType); int status = httpClient.executeMethod(filePost); // TODO Log.v("status--->", status + ""); InputStream in = filePost.getResponseBodyAsStream(); byte[] readStream = readStream(in); string = new String(readStream); } catch (Exception ex) { ex.printStackTrace(); } finally { filePost.releaseConnection(); } return string; }