package com.tiger.quicknews.http; import android.content.Context; import android.text.TextUtils; import android.util.Log; import org.apache.http.NameValuePair; import java.io.UnsupportedEncodingException; public class HttpUtil { // 网络连接部分 public static String postByHttpURLConnection(String strUrl, NameValuePair... nameValuePairs) { return CustomHttpURLConnection.PostFromWebByHttpURLConnection(strUrl, nameValuePairs); } public static String getByHttpURLConnection(String strUrl, NameValuePair... nameValuePairs) { return CustomHttpURLConnection.GetFromWebByHttpUrlConnection(strUrl, nameValuePairs); } public static String postByHttpClient(Context context, String strUrl, NameValuePair... nameValuePairs) throws Exception { String result = CustomHttpClient.PostFromWebByHttpClient(context, strUrl, nameValuePairs); return result; } public static String getByHttpClient(Context context, String strUrl, NameValuePair... nameValuePairs) throws Exception { String result = CustomHttpClient.getFromWebByHttpClient(context, strUrl, nameValuePairs); if (TextUtils.isEmpty(result)) { result = ""; } return result; } // 网络连接判断 /** * 判断是否有网络 */ public static boolean isNetworkAvailable(Context context) { return NetWorkHelper.isNetworkAvailable(context); } /** * 判断mobile网络是否可用 */ public static boolean isMobileDataEnable(Context context) { String TAG = "httpUtils.isMobileDataEnable()"; try { return NetWorkHelper.isMobileDataEnable(context); } catch (Exception e) { // TODO Auto-generated catch block Log.e(TAG, e.getMessage()); e.printStackTrace(); return false; } } /** * 判断wifi网络是否可用 */ public static boolean isWifiDataEnable(Context context) { String TAG = "httpUtils.isWifiDataEnable()"; try { return NetWorkHelper.isWifiDataEnable(context); } catch (Exception e) { // TODO Auto-generated catch block Log.e(TAG, e.getMessage()); e.printStackTrace(); return false; } } /** * 判断是否为漫�? */ public static boolean isNetworkRoaming(Context context) { return NetWorkHelper.isNetworkRoaming(context); } /** * 编码测试 */ public static void testCharset(String datastr) { try { String temp = new String(datastr.getBytes(), "GBK"); Log.v("TestCharset", "****** getBytes() -> GBK ******/n" + temp); temp = new String(datastr.getBytes("GBK"), "UTF-8"); Log.v("TestCharset", "****** GBK -> UTF-8 *******/n" + temp); temp = new String(datastr.getBytes("GBK"), "ISO-8859-1"); Log.v("TestCharset", "****** GBK -> ISO-8859-1 *******/n" + temp); temp = new String(datastr.getBytes("ISO-8859-1"), "UTF-8"); Log.v("TestCharset", "****** ISO-8859-1 -> UTF-8 *******/n" + temp); temp = new String(datastr.getBytes("ISO-8859-1"), "GBK"); Log.v("TestCharset", "****** ISO-8859-1 -> GBK *******/n" + temp); temp = new String(datastr.getBytes("UTF-8"), "GBK"); Log.v("TestCharset", "****** UTF-8 -> GBK *******/n" + temp); temp = new String(datastr.getBytes("UTF-8"), "ISO-8859-1"); Log.v("TestCharset", "****** UTF-8 -> ISO-8859-1 *******/n" + temp); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } } }