java http 请求的工具类
/*** Eclipse Class Decompiler plugin, copyright (c) 2016 Chen Chao (cnfree2000@hotmail.com) ***/
package com.ods.common.util;
import com.ods.common.util.MyFile;
import com.ods.common.util.PropUtil;
import com.ods.common.util.ProxyUtil;
import com.ods.common.util.StringUtil;
import java.io.BufferedReader;
import java.io.ByteArrayOutputStream;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.net.ConnectException;
import java.net.HttpURLConnection;
import java.net.Proxy;
import java.net.URL;
import java.nio.charset.Charset;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.UUID;
import java.util.Map.Entry;
import net.sf.json.JSONObject;
import org.apache.http.HttpHost;
import org.apache.http.client.config.RequestConfig;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.message.BasicNameValuePair;
import org.apache.http.util.EntityUtils;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.junit.Test;
import org.springframework.http.HttpStatus;
public class HttpUtil {
   private static Logger logger = LogManager.getLogger(HttpUtil.class.getName());
public static void main(String[] args) throws Exception {
      String content = "111";
      String url = "https://api.weixin.qq.com/cgi-bin/ticket/getticket?access_token=ACCESS_TOKEN&type=wx_card";
      String qw = sendGet(url);
      JSONObject object = JSONObject.fromObject(qw);
      System.out.println(object);
   }
@Test
   public void name() {
      String points_date = "2015-12-05 00:00:00";
      SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
      Date date = null;
try {
         date = sdf.parse(points_date);
      } catch (ParseException arg4) {
         arg4.printStackTrace();
      }
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
      points_date = format.format(date);
      System.out.println(points_date);
   }
public static JSONObject postMap(String url, Map<String, Object> headerMap, Map<String, Object> paramMap, String stringType) throws IOException {
      CloseableHttpClient httpclient = null;
      JSONObject responseJson = null;
      String ifproxy = PropUtil.getPropertyValue("ods.http.is.proxy", "0").replace("\"", "");
      if(!"0".equals(ifproxy)) {
         String postMethod = PropUtil.getPropertyValue("ods.http.proxy.server", "10.74.46.189:8080").replace("\"", "");
         String requestConfig = PropUtil.getPropertyValue("ods.http.proxy.not", "127.0.0.1").replace("\"", "");
         String[] hashMap = postMethod.split(":");
         String e = hashMap[0];
         boolean result = false;
         String[] entity = requestConfig.split(",");
int proxyPort;
         for(proxyPort = 0; proxyPort < entity.length; ++proxyPort) {
            if(url.indexOf(entity[proxyPort]) >= 0) {
               httpclient = HttpClients.custom().build();
               result = true;
               break;
            }
         }
if(!result) {
            proxyPort = Integer.valueOf(hashMap[1]).intValue();
            HttpHost proxy = new HttpHost(e, proxyPort);
            httpclient = HttpClients.custom().setProxy(proxy).build();
         }
      } else {
         httpclient = HttpClients.custom().build();
      }
HttpPost arg18 = new HttpPost(url);
      if(StringUtil.isNotEmpty(headerMap)) {
         Iterator arg19 = headerMap.entrySet().iterator();
while(arg19.hasNext()) {
            Entry arg21 = (Entry)arg19.next();
            arg18.setHeader((String)arg21.getKey(), (String)arg21.getValue());
         }
      }
RequestConfig arg20 = RequestConfig.custom().setSocketTimeout('').setConnectTimeout('').build();
      new HashMap();
try {
         arg18.setConfig(arg20);
         if("json".equals(stringType)) {
            if(StringUtil.isNotEmpty(paramMap)) {
               StringEntity arg23 = new StringEntity(JSONObject.fromObject(paramMap).toString(), "utf-8");
               arg23.setContentEncoding("utf-8");
               arg23.setContentType("application/json");
               arg18.setEntity(arg23);
            }
         } else {
            ArrayList arg22 = new ArrayList();
            if(StringUtil.isNotEmpty(paramMap)) {
               Iterator arg25 = paramMap.entrySet().iterator();
while(arg25.hasNext()) {
                  Entry arg27 = (Entry)arg25.next();
                  arg22.add(new BasicNameValuePair((String)arg27.getKey(), (String)arg27.getValue()));
               }
UrlEncodedFormEntity arg28 = new UrlEncodedFormEntity(arg22, "UTF-8");
               arg18.setEntity(arg28);
            }
         }
CloseableHttpResponse arg24 = httpclient.execute(arg18);
         if(arg24.getStatusLine().getStatusCode() == HttpStatus.OK.value() || arg24.getStatusLine().getStatusCode() == HttpStatus.ACCEPTED.value() || arg24.getStatusLine().getStatusCode() == HttpStatus.UNAUTHORIZED.value()) {
            String arg26 = EntityUtils.toString(arg24.getEntity(), "utf-8");
            responseJson = JSONObject.fromObject(arg26);
         }
      } catch (IOException arg16) {
         arg16.printStackTrace();
         logger.error("postMap请求出现异常,url:" + url + arg16);
      } finally {
         httpclient.close();
      }
return responseJson;
   }
public static String Post(String url, String param) throws Exception {
      Object in = null;
      String result = "";
      DataOutputStream out = null;
try {
         URL e = new URL(url);
         Proxy proxy = ProxyUtil.getHttpProxy(url);
         HttpURLConnection connection = null;
         if(proxy == null) {
            connection = (HttpURLConnection)e.openConnection();
         } else {
            connection = (HttpURLConnection)e.openConnection(proxy);
         }
connection.setDoInput(true);
         connection.setDoOutput(true);
         connection.setRequestMethod("POST");
         connection.setUseCaches(false);
         connection.setInstanceFollowRedirects(true);
         connection.setReadTimeout(300000);
         connection.setRequestProperty("Content-Type", "application/json;charset=utf-8");
         connection.connect();
         out = new DataOutputStream(connection.getOutputStream());
         out.write(param.getBytes("UTF-8"));
         out.flush();
         out.close();
         BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream()));
         StringBuffer sbf = new StringBuffer();
String lines;
         while((lines = reader.readLine()) != null) {
            lines = new String(lines.getBytes(), "utf-8");
            sbf.append(lines);
         }
result = sbf.toString();
         reader.close();
         connection.disconnect();
      } catch (ConnectException arg20) {
         logger.error("Post请求出现异常:连接超时,url:" + url + arg20);
      } catch (Exception arg21) {
         logger.error("Post请求出现异常,url:" + url + arg21);
      } finally {
         try {
            if(out != null) {
               out.close();
            }
if(in != null) {
               ((BufferedReader)in).close();
            }
         } catch (IOException arg19) {
            arg19.printStackTrace();
         }
}
return result;
   }
public static String Post(String url, String param, String charsetname) throws Exception {
      if(StringUtil.isNotEmpty(charsetname)) {
         charsetname = "UTF-8";
      }
Object in = null;
      String result = "";
      DataOutputStream out = null;
try {
         URL e = new URL(url);
         Proxy proxy = ProxyUtil.getHttpProxy(url);
         HttpURLConnection connection = null;
         if(proxy == null) {
            connection = (HttpURLConnection)e.openConnection();
         } else {
            connection = (HttpURLConnection)e.openConnection(proxy);
         }
connection.setDoInput(true);
         connection.setDoOutput(true);
         connection.setRequestMethod("POST");
         connection.setUseCaches(false);
         connection.setInstanceFollowRedirects(true);
         connection.setRequestProperty("Content-Type", "application/json;charset=" + charsetname);
         connection.connect();
         out = new DataOutputStream(connection.getOutputStream());
         out.write(param.getBytes(charsetname));
         out.flush();
         out.close();
         BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream(), charsetname));
         StringBuffer sbf = new StringBuffer();
String lines;
         while((lines = reader.readLine()) != null) {
            String iso = new String(lines.getBytes("UTF-8"), "ISO-8859-1");
            lines = new String(iso.getBytes("ISO-8859-1"), "UTF-8");
            String iso1 = new String(lines.getBytes("gbk"), "ISO-8859-1");
            String lines1 = new String(iso1.getBytes("ISO-8859-1"), "gbk");
            logger.error("GB2312:" + Charset.forName("GB2312").newEncoder().canEncode(lines));
            logger.error("ISO-8859-1:" + Charset.forName("ISO-8859-1").newEncoder().canEncode(lines));
            logger.error("gbk:" + Charset.forName("gbk").newEncoder().canEncode(lines));
            logger.error("utf-8:" + Charset.forName("utf-8").newEncoder().canEncode(lines));
            sbf.append(lines);
            logger.error("lines:" + lines);
            logger.error("lines1:" + lines1);
         }
result = sbf.toString();
         reader.close();
         connection.disconnect();
      } catch (ConnectException arg24) {
         logger.error("Post请求出现异常:连接超时,url:" + url + arg24);
      } catch (Exception arg25) {
         logger.error("Post请求出现异常,url:" + url + arg25);
      } finally {
         try {
            if(out != null) {
               out.close();
            }
if(in != null) {
               ((BufferedReader)in).close();
            }
         } catch (IOException arg23) {
            arg23.printStackTrace();
         }
}
return result;
   }
public static String Post(String url, String postData, Map<String, String> headers) throws IOException {
      URL u = null;
      HttpURLConnection con = null;
      InputStream inputStream = null;
      OutputStreamWriter outStream = null;
      ByteArrayOutputStream baos = null;
      String result = null;
try {
         u = new URL(url);
         con = (HttpURLConnection)u.openConnection();
         con.setRequestMethod("POST");
         con.setDoOutput(true);
         con.setDoInput(true);
         con.setUseCaches(false);
         con.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
         con.setRequestProperty("connection", "Keep-Alive");
         con.setRequestProperty("user-agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1;SV1)");
         if(headers != null && !headers.isEmpty()) {
            Iterator arg9 = headers.keySet().iterator();
while(arg9.hasNext()) {
               String e = (String)arg9.next();
               con.setRequestProperty(e, (String)headers.get(e));
            }
         }
outStream = new OutputStreamWriter(con.getOutputStream());
         outStream.write(postData);
         outStream.flush();
         outStream.close();
         if(con.getResponseCode() == 200) {
            inputStream = con.getInputStream();
            baos = new ByteArrayOutputStream();
            boolean e1 = true;
int e2;
            while((e2 = inputStream.read()) != -1) {
               baos.write(e2);
            }
result = baos.toString("utf-8");
         } else {
            logger.error("请求返回错误码:" + con.getResponseCode());
         }
      } catch (Exception arg13) {
         arg13.printStackTrace();
      } finally {
         if(con != null) {
            con.disconnect();
         }
if(inputStream != null) {
            inputStream.close();
         }
if(outStream != null) {
            outStream.close();
         }
if(baos != null) {
            baos.close();
         }
}
return result;
   }
public static String sendGet(String url) {
      String result = "";
      BufferedReader in = null;
      HttpURLConnection conn = null;
try {
         URL realUrl = new URL(url);
         Proxy proxy = ProxyUtil.getHttpProxy(url);
         if(proxy == null) {
            conn = (HttpURLConnection)realUrl.openConnection();
         } else {
            conn = (HttpURLConnection)realUrl.openConnection(proxy);
         }
conn.setRequestProperty("accept", "**");
         conn.setRequestProperty("connection", "Keep-Alive");
         conn.setRequestProperty("user-agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1)");
         conn.setDoOutput(true);
         conn.setDoInput(true);
         conn.setRequestProperty("contentType", "UTF-8");
         outputStream = conn.getOutputStream();
         outputStream.write(param.getBytes("UTF-8"));
         outputStream.flush();
String line;
         for(in = new BufferedReader(new InputStreamReader(conn.getInputStream(), "utf-8")); (line = in.readLine()) != null; result = result + "\n" + line) {
            ;
         }
      } catch (ConnectException arg23) {
         logger.error("sendPost请求出现异常:连接超时" + url + arg23);
      } catch (Exception arg24) {
         logger.error("sendPost请求出现异常,url:" + url + arg24);
      } finally {
         if(conn != null) {
            conn.disconnect();
         }
try {
            if(in != null) {
               in.close();
            }
         } catch (IOException arg22) {
            arg22.printStackTrace();
         }
try {
            if(outputStream != null) {
               outputStream.close();
            }
         } catch (IOException arg21) {
            arg21.printStackTrace();
         }
}
return result;
   }
public static JSONObject uploadMedia(String Url, String filePath) {
      JSONObject jsonObj = null;
      BufferedReader reader = null;
try {
         URL e = new URL(Url);
         String result = null;
         File file = new File(filePath);
         if(!file.exists() || !file.isFile()) {
            throw new IOException("上传的文件不存在");
         }
Proxy proxy = ProxyUtil.getHttpProxy(Url);
         HttpURLConnection conn = null;
         if(proxy == null) {
            conn = (HttpURLConnection)e.openConnection();
         } else {
            conn = (HttpURLConnection)e.openConnection(proxy);
         }
conn.setRequestMethod("POST");
         conn.setDoInput(true);
         conn.setDoOutput(true);
         conn.setUseCaches(false);
         conn.setRequestProperty("Connection", "Keep-Alive");
         conn.setRequestProperty("Charset", "UTF-8");
         String BOUNDARY = "----------" + System.currentTimeMillis();
         conn.setRequestProperty("Content-Type", "multipart/form-data; boundary=" + BOUNDARY);
         StringBuilder sb = new StringBuilder();
         sb.append("--");
         sb.append(BOUNDARY);
         sb.append("\r\n");
         sb.append("Content-Disposition: form-data;name=\"file\";filename=\"" + file.getName() + "\"\r\n");
         sb.append("Content-Type:application/octet-stream\r\n\r\n");
         byte[] head = sb.toString().getBytes("utf-8");
         DataOutputStream out = new DataOutputStream(conn.getOutputStream());
         out.write(head);
         DataInputStream in = new DataInputStream(new FileInputStream(file));
         boolean bytes = false;
         byte[] bufferOut = new byte[1024];
int bytes1;
         while((bytes1 = in.read(bufferOut)) != -1) {
            out.write(bufferOut, 0, bytes1);
         }
in.close();
         byte[] foot = ("\r\n--" + BOUNDARY + "--\r\n").getBytes("utf-8");
         out.write(foot);
         out.flush();
         out.close();
         StringBuffer buffer = new StringBuffer();
         reader = new BufferedReader(new InputStreamReader(conn.getInputStream()));
         String line = null;
while((line = reader.readLine()) != null) {
            buffer.append(line);
         }
if(result == null) {
            result = buffer.toString();
         }
jsonObj = JSONObject.fromObject(result);
      } catch (ConnectException arg28) {
         logger.error("uploadMedia请求出现异常:连接超时,url:" + Url + arg28);
      } catch (Exception arg29) {
         logger.error("uploadMedia请求出现异常,url:" + Url + arg29);
      } finally {
         if(reader != null) {
            try {
               reader.close();
            } catch (IOException arg27) {
               arg27.printStackTrace();
            }
         }
}
return jsonObj;
   }
public static MyFile downloadMedia(String url) {
      Object bis = null;
      MyFile mf = new MyFile();
try {
         URL e = new URL(url);
         Proxy proxy = ProxyUtil.getHttpProxy(url);
         HttpURLConnection conn = null;
         if(proxy == null) {
            conn = (HttpURLConnection)e.openConnection();
         } else {
            conn = (HttpURLConnection)e.openConnection(proxy);
         }
conn.setDoInput(true);
         conn.setRequestMethod("GET");
         System.setProperty("sun.net.client.defaultConnectTimeout", "30000");
         System.setProperty("sun.net.client.defaultReadTimeout", "30000");
         conn.connect();
         String fileExt = conn.getHeaderField("Content-Type");
         fileExt = getFileExt(fileExt);
         UUID uuid = UUID.randomUUID();
         InputStream is = conn.getInputStream();
         mf.setFileName(uuid + fileExt);
         mf.setInStream(is);
         conn.disconnect();
      } catch (ConnectException arg8) {
         logger.error("downloadMedia请求出现异常:连接超时,url:" + url + arg8);
      } catch (Exception arg9) {
         logger.error("downloadMedia请求出现异常,url:" + url + arg9);
      }
return mf;
   }
public static String uploadByUrlInputream(InputStream inputStream, String fileName, String surl) {
      BufferedReader reader = null;
      String result = null;
try {
         URL e = new URL(surl);
         Proxy proxy = ProxyUtil.getHttpProxy(surl);
         HttpURLConnection con = null;
         if(proxy == null) {
            con = (HttpURLConnection)e.openConnection();
         } else {
            con = (HttpURLConnection)e.openConnection(proxy);
         }
con.setRequestMethod("POST");
         con.setDoInput(true);
         con.setDoOutput(true);
         con.setUseCaches(false);
         con.setRequestProperty("Connection", "Keep-Alive");
         con.setRequestProperty("Charset", "UTF-8");
         String BOUNDARY = "----------" + System.currentTimeMillis();
         con.setRequestProperty("Content-Type", "multipart/form-data; boundary=" + BOUNDARY);
         StringBuilder sb = new StringBuilder();
         sb.append("--");
         sb.append(BOUNDARY);
         sb.append("\r\n");
         sb.append("Content-Disposition: form-data;name=\"file\";filename=\"" + fileName + "\"\r\n");
         sb.append("Content-Type:application/octet-stream\r\n\r\n");
         byte[] head = sb.toString().getBytes("utf-8");
         DataOutputStream out = new DataOutputStream(con.getOutputStream());
         out.write(head);
         DataInputStream in = new DataInputStream(inputStream);
         boolean bytes = false;
         byte[] bufferOut = new byte[1024];
int bytes1;
         while((bytes1 = in.read(bufferOut)) != -1) {
            out.write(bufferOut, 0, bytes1);
         }
in.close();
         byte[] foot = ("\r\n--" + BOUNDARY + "--\r\n").getBytes("utf-8");
         out.write(foot);
         out.flush();
         out.close();
         StringBuffer buffer = new StringBuffer();
         reader = new BufferedReader(new InputStreamReader(con.getInputStream()));
         String line = null;
while((line = reader.readLine()) != null) {
            buffer.append(line);
         }
if(result == null) {
            result = buffer.toString();
         }
      } catch (ConnectException arg27) {
         logger.error("uploadByUrlInputream请求出现异常:连接超时,url:" + surl + arg27);
      } catch (Exception arg28) {
         logger.error("uploadByUrlInputream请求出现异常,url:" + surl + arg28);
      } finally {
         if(reader != null) {
            try {
               reader.close();
            } catch (IOException arg26) {
               arg26.printStackTrace();
            }
         }
}
return result;
   }
public static String uploadByInputream(FileInputStream fileStream, String fileName, String surl) {
      BufferedReader reader = null;
      String result = null;
try {
         URL e = new URL(surl);
         Proxy proxy = ProxyUtil.getHttpProxy(surl);
         HttpURLConnection con = null;
         if(proxy == null) {
            con = (HttpURLConnection)e.openConnection();
         } else {
            con = (HttpURLConnection)e.openConnection(proxy);
         }
con.setRequestMethod("POST");
         con.setDoInput(true);
         con.setDoOutput(true);
         con.setUseCaches(false);
         con.setRequestProperty("Connection", "Keep-Alive");
         con.setRequestProperty("Charset", "UTF-8");
         String BOUNDARY = "----------" + System.currentTimeMillis();
         con.setRequestProperty("Content-Type", "multipart/form-data; boundary=" + BOUNDARY);
         StringBuilder sb = new StringBuilder();
         sb.append("--");
         sb.append(BOUNDARY);
         sb.append("\r\n");
         sb.append("Content-Disposition: form-data;name=\"file\";filename=\"" + fileName + "\"\r\n");
         sb.append("Content-Type:application/octet-stream\r\n\r\n");
         byte[] head = sb.toString().getBytes("utf-8");
         DataOutputStream out = new DataOutputStream(con.getOutputStream());
         out.write(head);
         DataInputStream in = new DataInputStream(fileStream);
         boolean bytes = false;
         byte[] bufferOut = new byte[1024];
int bytes1;
         while((bytes1 = in.read(bufferOut)) != -1) {
            out.write(bufferOut, 0, bytes1);
         }
in.close();
         byte[] foot = ("\r\n--" + BOUNDARY + "--\r\n").getBytes("utf-8");
         out.write(foot);
         out.flush();
         out.close();
         StringBuffer buffer = new StringBuffer();
         reader = new BufferedReader(new InputStreamReader(con.getInputStream()));
         String line = null;
while((line = reader.readLine()) != null) {
            buffer.append(line);
         }
if(result == null) {
            result = buffer.toString();
         }
      } catch (ConnectException arg27) {
         logger.error("uploadByInputream请求出现异常:连接超时,url:" + surl + arg27);
      } catch (Exception arg28) {
         logger.error("uploadByInputream请求出现异常,url:" + surl + arg28);
      } finally {
         if(reader != null) {
            try {
               reader.close();
            } catch (IOException arg26) {
               arg26.printStackTrace();
            }
         }
}
return result;
   }
public static String uploadByInputream(InputStream fileStream, String fileName, String surl) {
      BufferedReader reader = null;
      String result = null;
try {
         URL e = new URL(surl);
         Proxy proxy = ProxyUtil.getHttpProxy(surl);
         HttpURLConnection con = null;
         if(proxy == null) {
            con = (HttpURLConnection)e.openConnection();
         } else {
            con = (HttpURLConnection)e.openConnection(proxy);
         }
con.setRequestMethod("POST");
         con.setDoInput(true);
         con.setDoOutput(true);
         con.setUseCaches(false);
         con.setRequestProperty("Connection", "Keep-Alive");
         con.setRequestProperty("Charset", "UTF-8");
         String BOUNDARY = "----------" + System.currentTimeMillis();
         con.setRequestProperty("Content-Type", "multipart/form-data; boundary=" + BOUNDARY);
         StringBuilder sb = new StringBuilder();
         sb.append("--");
         sb.append(BOUNDARY);
         sb.append("\r\n");
         sb.append("Content-Disposition: form-data;name=\"file\";filename=\"" + fileName + "\"\r\n");
         sb.append("Content-Type:application/octet-stream\r\n\r\n");
         byte[] head = sb.toString().getBytes("utf-8");
         DataOutputStream out = new DataOutputStream(con.getOutputStream());
         out.write(head);
         DataInputStream in = new DataInputStream(fileStream);
         boolean bytes = false;
         byte[] bufferOut = new byte[1024];
int bytes1;
         while((bytes1 = in.read(bufferOut)) != -1) {
            out.write(bufferOut, 0, bytes1);
         }
in.close();
         byte[] foot = ("\r\n--" + BOUNDARY + "--\r\n").getBytes("utf-8");
         out.write(foot);
         out.flush();
         out.close();
         StringBuffer buffer = new StringBuffer();
         reader = new BufferedReader(new InputStreamReader(con.getInputStream()));
         String line = null;
while((line = reader.readLine()) != null) {
            buffer.append(line);
         }
if(result == null) {
            result = buffer.toString();
         }
      } catch (ConnectException arg27) {
         logger.error("uploadByInputream请求出现异常:连接超时,url:" + surl + arg27);
      } catch (Exception arg28) {
         logger.error("uploadByInputream请求出现异常,url:" + surl + arg28);
      } finally {
         if(reader != null) {
            try {
               reader.close();
            } catch (IOException arg26) {
               arg26.printStackTrace();
            }
         }
}
return result;
   }
public static String getFileExt(String contentType) {
      String fileExt = "";
      if(!"image/jpeg".equals(contentType) && !"image/jpg".equals(contentType)) {
         if("image/png".equals(contentType)) {
            fileExt = ".png";
         } else if("audio/mpeg".equals(contentType)) {
            fileExt = ".mp3";
         } else if("audio/amr".equals(contentType)) {
            fileExt = ".amr";
         } else if("video/mp4".equals(contentType)) {
            fileExt = ".mp4";
         } else if("video/mpeg4".equals(contentType)) {
            fileExt = ".mp4";
         }
      } else {
         fileExt = ".jpg";
      }
return fileExt;
   }
}
java http 请求的工具类的更多相关文章
- Java httpclent请求httpclentUtils工具类
		
第一种写法: import java.io.IOException; import java.io.InterruptedIOException; import java.io.Unsupported ...
 - HttpUtils 用于进行网络请求的工具类
		
原文:http://www.open-open.com/code/view/1437537162631 import java.io.BufferedReader; import java.io.By ...
 - HTTP请求客户端工具类
		
1.maven 引入依赖 <dependency> <groupId>commons-httpclient</groupId> <artifactId> ...
 - 发送http请求和https请求的工具类
		
package com.haiyisoft.cAssistant.utils; import java.io.IOException;import java.util.ArrayList; impor ...
 - Rhino+envjs-1.2.js 在java运行网站js 工具类
		
java爬虫遇到个页面加密的东西,找了些资料学习学习 做了个java运行js的工具类,希望对大家有用,其中用到client(获取js)可以自行换成自己的client.主要是用了 Rhino就是Java ...
 - java中常用的工具类(一)
		
我们java程序员在开发项目的是常常会用到一些工具类.今天我汇总了一下java中常用的工具方法.大家可以在项目中使用.可以收藏!加入IT江湖官方群:383126909 我们一起成长 一.String工 ...
 - Java学习-041-颜色工具类(RGB,HEX)
		
在日常的网页开发中,经常需要进行颜色数值获取.转换,例如获取红色,获取蓝色,获取绿色,RGB转十六进制颜色,十六进制颜色转RGB等,因而在学习过程中,写了一个小工具类,仅供各位小主参考! 多不闲言,直 ...
 - JAVA中封装JSONUtils工具类及使用
		
在JAVA中用json-lib-2.3-jdk15.jar包中提供了JSONObject和JSONArray基类,用于JSON的序列化和反序列化的操作.但是我们更习惯将其进一步封装,达到更好的重用. ...
 - JAVA自动生成正则表达式工具类
		
经过很久的努力,终于完成了JAVA自动生成正则表达式工具类.还记得之前需要正则,老是从网上找吗?找了想修改也不会修改.现在不用再为此烦恼了,使用此生成类轻松搞定所有正则表达式.赶快在同事面前炫一下吧. ...
 
随机推荐
- elasticsearch(1) 安装和使用
			
一.简介 Elasticsearch是一个基于Apache Lucene(TM)的开源搜索引擎.无论在开源还是专有领域,Lucene可以被认为是迄今为止最先进.性能最好的.功能最全的搜索引擎库. 但是 ...
 - TkbmMWClientQuery的计算字段在CalcFields事件触发次数太多
			
kbmmw有两处BUG和作者提下,一个是TkbmMWClientQuery的计算字段在CalcFields事件触发次数太多,另一个是在TkbmMemTable的加载数据时字段会执行OnValidate ...
 - 微信小程序实际开发中学习
			
三个概念 微信:就是一个聊天工具 微信公众号:企业或个人用于管理其粉丝/用户的应用(类似于APP) 微信小程序:不需要下载安装直接可以使用的软件/应用/APP 小程序与公众号的区别: 定位不同(小程序 ...
 - java中对类中成员的排序
			
要求:编写一个程序.程序中定义一个类circle,其中有数据成员radius:创建一个有5个circle型元素的数组,其radius值分别为2.10.8.4.121.调用Arrays.sort()给这 ...
 - ASP.NET项目答辩系统课件使用中的问题记录
			
使用软件:VS2008 模块一:登录模块 1-08 问题:显示属性“background”不是元素"td"的有效属性 解决:style="background-image ...
 - SpringBoot的学习【5.Spring Boot 的配置文件】
			
1.配置文件的名称 Spring Boot 会将两种名称的文件默认为项目的全局配置文件.配置文件的名字是固定的. application.properties application.yml 2.配置 ...
 - python基础---列表生成器、迭代器等
			
一.列表生成式 用来创建list的表达式,相当于for循环的简写形式 语法: [表达式 for循环 判断条件] ''' 普通写法 ''' def test(): l= [] for i in rang ...
 - 如何使用idea给系统平台添加子应用和应用的模块
			
1.添加模块smartcity-portal,由于模块是在smartcity-framework工程下的,所以按照图片所示添加 2.smartcity-portal模块添加完成后,由于portal-d ...
 - Linux 环境下安装RabbitMQ的步骤
			
#下载erlangcd /usr/local/devwget wget http://erlang.org/download/otp_src_17.5.tar.gz # 解压tar -xzvf otp ...
 - iOS CATransition 动画的简单使用
			
下面是实现的代码 //选择动画 - (IBAction)selectAnimationTypeButton:(id)sender { UIButton *button = sender; animat ...