顺德网站设计,企业网站设计风格,男女生做羞羞事情的网站,wordpress用户修改邮箱开发功能#xff1a; web前端提交上传文件 — a服务器接收 — 转发到b服务器进行文件处理 下面是简单实现的代码#xff0c;具体细节优化根本自己的需求更改。 public String handleResponse(HttpServletRequest request, HttpServletResponse response)throws Unsup… 开发功能 web前端提交上传文件 — a服务器接收 — 转发到b服务器进行文件处理 下面是简单实现的代码具体细节优化根本自己的需求更改。 public String handleResponse(HttpServletRequest request, HttpServletResponse response)throws UnsupportedEncodingException, IOException {String method request.getMethod();String url b服务器的api url;if (method.equals(POST)) { String contentType application/json; charsetUTF-8; if (request.getContentType() ! null) contentType request.getContentType();// 会获取到空指针 MapString, String[] tmp new HashMap(request.getParameterMap()); if (contentType.toLowerCase().startsWith(multipart/)) { MultipartHttpServletRequest multipartRequest WebUtils.getNativeRequest(request, MultipartHttpServletRequest.class); MultipartFile file multipartRequest.getFile(file); return httpClientUpload(url, file, tmp); } } return null; } 123456789101112131415161718123456789101112131415161718public String httpClientUpload(String url, MultipartFile file, MapString, String[] params)throws ClientProtocolException, IOException {HttpClient httpclient new DefaultHttpClient();// 请求处理页面 HttpPost httppost new HttpPost(url); // 创建待处理的文件 String fileName file.getOriginalFilename(); ContentBody files new ByteArrayBody(file.getBytes(), fileName); // 对请求的表单域进行填充 MultipartEntity reqEntity new MultipartEntity(); reqEntity.addPart(file, files); if (params ! null) {//这里草草处理values[] for (String key : params.keySet()) { String[] values params.get(key); for (int i 0; i values.length; i) { String value values[i]; try { value URLEncoder.encode(value, UTF-8); reqEntity.addPart(key, new StringBody(value)); } catch (UnsupportedEncodingException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } } // 设置请求 httppost.setEntity(reqEntity); // 执行 HttpResponse response httpclient.execute(httppost); if (HttpStatus.SC_OK response.getStatusLine().getStatusCode()) { HttpEntity entity response.getEntity(); return EntityUtils.toString(entity, Charset.forName(UTF-8)); } return null; } 12345678910111213141516171819202122232425262728293031323334353637 12345678910111213141516171819202122232425262728293031323334353637 http://bbs.bxzc123.com/forum.php?modviewthreadtid244545http://bbs.bxzc123.com/forum.php?modviewthreadtid244541http://bbs.bxzc123.com/forum.php?modviewthreadtid244538http://bbs.bxzc123.com/forum.php?modviewthreadtid244527http://bbs.bxzc123.com/forum.php?modviewthreadtid244528http://bbs.bxzc123.com/forum.php?modviewthreadtid244529http://bbs.bxzc123.com/forum.php?modviewthreadtid244530 转载于:https://www.cnblogs.com/sy646et/p/7266017.html