List of usage examples for java.io UnsupportedEncodingException printStackTrace
public void printStackTrace()
From source file:Main.java
public static UrlEncodedFormEntity buildUrlEncodedFormEntity(Map<String, String> keyValuePairs, String encoding) {/*from ww w. j a v a 2 s . com*/ if (encoding == null) { encoding = HTTP.UTF_8; } List<BasicNameValuePair> params = new ArrayList<BasicNameValuePair>(); if (keyValuePairs != null) { Set<String> keys = keyValuePairs.keySet(); for (String key : keys) { String value = keyValuePairs.get(key); BasicNameValuePair param = new BasicNameValuePair(key, value); params.add(param); } } try { return new UrlEncodedFormEntity(params, encoding); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } return null; }
From source file:Main.java
public static String getEncoder(String str) { try {// www.ja va 2s. co m return URLEncoder.encode(str, "UTF-8"); } catch (UnsupportedEncodingException e) { // TODO Auto-generated catch block e.printStackTrace(); } return null; }
From source file:Main.java
public static String makeRequest1(String url, String json) { Log.v(TAG, "URL-->" + url); Log.v(TAG, "input-->" + json); try {/*from w w w . j a v a 2 s . co m*/ HttpPost httpPost = new HttpPost(url); httpPost.setEntity(new StringEntity(json)); HttpResponse httpResponse = new DefaultHttpClient().execute(httpPost); // receive response as inputStream InputStream inputStream = httpResponse.getEntity().getContent(); // convert inputstream to string if (inputStream != null) { String result = convertInputStreamToString(inputStream); Log.v(TAG, "output-->" + result); return result; } } catch (UnsupportedEncodingException e) { e.printStackTrace(); } catch (ClientProtocolException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } return ""; }
From source file:com.aqnote.shared.cryptology.digest.SM.java
public final static String sm3(String src) { if (StringUtils.isBlank(src)) return ""; try {/* www. j av a 2s. co m*/ return sm3(src.getBytes(DEFAULT_CHARSET)); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } return ""; }
From source file:Main.java
public static boolean logout() { String baseUrl = "http://10.6.8.2/cgi-bin/srun_portal?action=logout&ac_id=1"; try {/*from ww w . j a v a2s .c om*/ HttpGet getMethod = new HttpGet(baseUrl); getMethod.addHeader("Accept", "*/*"); //getMethod.addHeader("Accept-Language", "zh-cn"); //getMethod.addHeader("Referer", "http://202.117.2.41/index.html"); //getMethod.addHeader("Content-Type", "application/x-www-form-urlencoded"); //getMethod.addHeader("Accept-Encoding", "gzip, deflate"); //getMethod.addHeader("User-Agent", "Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.1; Trident/6.0)"); getMethod.addHeader("Host", "10.6.8.2"); //getMethod.addHeader("DNT", "1"); HttpClient httpClient = new DefaultHttpClient(); HttpResponse response = httpClient.execute(getMethod); Log.i(TAG, "Sending message....."); HttpEntity httpEntity = response.getEntity(); if (response.getStatusLine().getStatusCode() == 200) { String message = EntityUtils.toString(httpEntity); Log.i(TAG, "Logout succeed!!! message=" + message); return true; } } catch (UnsupportedEncodingException e) { e.printStackTrace(); } catch (ClientProtocolException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } Log.i(TAG, "Logout failed!!!"); return false; }
From source file:Main.java
public static String makeRequest55(String url, String json) { Log.v(TAG, "URL-->" + url); Log.v(TAG, "input-->" + json); try {/*from w w w .j a v a 2s. c o m*/ HttpPost httpPost = new HttpPost(url); httpPost.setEntity(new StringEntity(json)); httpPost.setHeader("Accept", "application/json"); httpPost.setHeader("Content-type", "application/json"); //text/html HttpResponse httpResponse = new DefaultHttpClient().execute(httpPost); // receive response as inputStream InputStream inputStream = httpResponse.getEntity().getContent(); // convert inputstream to string if (inputStream != null) { String result = convertInputStreamToString(inputStream); Log.v(TAG, "output-->" + result); return result; } } catch (UnsupportedEncodingException e) { e.printStackTrace(); } catch (ClientProtocolException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } return ""; }
From source file:Main.java
public static String makeRequest3(String url, String json) { Log.v(TAG, "URL-->" + url); Log.v(TAG, "input-->" + json); try {//from ww w . j a va 2 s .c o m HttpPost httpPost = new HttpPost(url); httpPost.setEntity(new StringEntity(json)); //httpPost.setHeader("sessionToken",AuthToken); // httpPost.setHeader("Accept", "application/json"); // httpPost.setHeader("Content-type", "application/json"); //text/html HttpResponse httpResponse = new DefaultHttpClient().execute(httpPost); // receive response as inputStream InputStream inputStream = httpResponse.getEntity().getContent(); // convert inputstream to string if (inputStream != null) { String result = convertInputStreamToString(inputStream); Log.d("tag", "outputtttttttttt-->" + result); return result; } } catch (UnsupportedEncodingException e) { e.printStackTrace(); } catch (ClientProtocolException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } return ""; }
From source file:Main.java
public static String makeRequest(String url, String json) { Log.v(TAG, "URL-->" + url); Log.v(TAG, "input-->" + json); try {/*from ww w. ja v a 2s.c o m*/ HttpPost httpPost = new HttpPost(url); httpPost.setEntity(new StringEntity(json)); httpPost.setHeader("Accept", "application/json"); httpPost.setHeader("Content-type", "application/json"); httpPost.setHeader("sessionToken", "61"); //text/html HttpResponse httpResponse = new DefaultHttpClient().execute(httpPost); // receive response as inputStream InputStream inputStream = httpResponse.getEntity().getContent(); // convert inputstream to string if (inputStream != null) { String result = convertInputStreamToString(inputStream); Log.v(TAG, "output-->" + result); return result; } } catch (UnsupportedEncodingException e) { e.printStackTrace(); } catch (ClientProtocolException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } return ""; }
From source file:Main.java
public static String getNewString(String str) { byte[] data = str.getBytes(); int index = data.length; for (int i = 0; i < data.length; i++) { if (data[i] < 48 || data[i] > 57) { index = i;//from w w w .ja va 2s . c o m break; } } byte[] temp = new byte[index]; System.arraycopy(data, 0, temp, 0, index); String res; try { res = new String(temp, "GBK"); } catch (UnsupportedEncodingException e) { // TODO Auto-generated catch block e.printStackTrace(); return ""; } return res; }
From source file:Main.java
public static String encodeParam(Map<String, String> params) { if (params == null) return ""; StringBuilder sb = new StringBuilder(); for (String key : params.keySet()) { Object val = params.get(key); if (sb.length() != 0) sb.append("&"); if (val instanceof Long[]) { Long[] longval = (Long[]) val; try { for (int i = 0; i < longval.length; i++) { String valStr = (val == null) ? "" : URLEncoder.encode(longval[i].toString(), "utf-8"); if (i != longval.length - 1) sb.append(key + "=" + valStr + "&"); else sb.append(key + "=" + valStr); }//w ww . ja v a2 s. co m } catch (UnsupportedEncodingException e) { e.printStackTrace(); } } else { try { String valStr = (val == null) ? "" : URLEncoder.encode(val.toString(), "utf-8"); sb.append(key + "=" + valStr); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } } } return sb.toString(); }