android HTTP发送及MD5加密收集
2016-03-16 11:43
447 查看
发送部分:
MD5加密部分:
public void MyFunction{ HttpClient httpclient = new DefaultHttpClient(); //你的URL HttpPost httppost = new HttpPost("http://www.eoeandroid.com/post_datas.php"); try { List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2); //Your DATA nameValuePairs.add(new BasicNameValuePair("id", "12345")); nameValuePairs.add(new BasicNameValuePair("stringdata", "eoeAndroid.com is Cool!")); httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs)); HttpResponse response; response=httpclient.execute(httppost); } catch (ClientProtocolException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } }
MD5加密部分:
public static String md5(String string) { byte[] hash; try { hash = MessageDigest.getInstance("MD5").digest(string.getBytes("UTF-8")); } catch (NoSuchAlgorithmException e) { throw new RuntimeException("Huh, MD5 should be supported?", e); } catch (UnsupportedEncodingException e) { throw new RuntimeException("Huh, UTF-8 should be supported?", e); } StringBuilder hex = new StringBuilder(hash.length * 2); for (byte b : hash) { if ((b & 0xFF) < 0x10) hex.append("0"); hex.append(Integer.toHexString(b & 0xFF)); } return hex.toString(); }
相关文章推荐
- 【Android】Http Digest 认证在android平台的实现
- 创建OpenStack外部网络并分配浮动IP
- iOS开发之runtime的运用-获取当前网络状态
- http的500,502,504错误
- http错误代码含义:
- http response乱码的真相 response重定向地址栏乱码
- IOS网络图片缓存详解
- [上下界网络流判定] BZOJ 2406 矩阵
- 新浪微博中遇到的网络问题
- 集线器、交换机、路由器、网关的作用与区别
- TCP/IP入门(4)--应用层
- TCP/IP入门(3)---运输层 据说是面试最主要的部分~~~
- TCP/IP入门(2)
- HttpServletResponse和HttpServletRequest常见应用
- Xcode7 使用NSURLSession发送HTTP请求的问题
- TCP/IP入门(1) 链路层
- http协议详解
- 记Outlook插件与Web页面交互的各种坑 (含c# HttpWebRequest 连接https 的完美解决方法)
- git 网上拉代码遇到 error: RPC failed; result=18, HTTP code = 200 | 2.12 MiB/s
- cocos2dx之HTTP开发