美文网首页
Android http协议转换https协议 6.0以下版本

Android http协议转换https协议 6.0以下版本

作者: 黑狼_佩恩 | 来源:发表于2019-06-04 13:44 被阅读0次

方法1:只需要在启动程序加载界面前添加下面代码

SSLSocketFactory.getSocketFactory().setHostnameVerifier(new AllowAllHostnameVerifier());

方法2:在网络请求数据时,添加自定义证书,请求是添加:

/**

* 自定义证书,HTTPS连接

*/ 

public static void GetNetWork() { 

    try { 

        String path = "https://192.168.1.123:8080/index.html"; 

        BasicHttpParams params = new BasicHttpParams(); 

        HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1); 

        HttpProtocolParams.setContentCharset(params, 

                HTTP.DEFAULT_CONTENT_CHARSET); 

        HttpProtocolParams.setUseExpectContinue(params, true); 

        SSLSocketFactory.getSocketFactory().setHostnameVerifier( 

                new AllowAllHostnameVerifier()); 

        SchemeRegistry schReg = new SchemeRegistry(); 

        schReg.register(new Scheme("http", PlainSocketFactory 

                .getSocketFactory(), 80)); 

        schReg.register(new Scheme("https", SSLTrustAllSocketFactory 

                .getSocketFactory(), 443)); 

        ClientConnectionManager connMgr = new ThreadSafeClientConnManager( 

                params, schReg); 

        DefaultHttpClient client = new DefaultHttpClient(connMgr, params); 

        HttpGet request = new HttpGet(path); 

        HttpResponse httpResponse = client.execute(request); 

        int responseCode = httpResponse.getStatusLine().getStatusCode(); 

        String message = httpResponse.getStatusLine().getReasonPhrase(); 

        HttpEntity entity = httpResponse.getEntity(); 

        if (responseCode == 200 && entity != null) { 

            Log.e("log", entity.toString()); 

        } 

    } catch (MalformedURLException e) { 

        e.printStackTrace(); 

    } catch (ClientProtocolException e) { 

        e.printStackTrace(); 

    } catch (IOException e) { 

        e.printStackTrace(); 

    } 

转载自  https://blog.csdn.net/qq_25462179/article/details/80264293

https://blog.csdn.net/u012929068/article/details/54910610 参考。

相关文章

  • Android http协议转换https协议 6.0以下版本

    方法1:只需要在启动程序加载界面前添加下面代码 SSLSocketFactory.getSocketFactory...

  • HTTP 深入探究

    【前言】以下源于慕课网《大话HTTP协议》课程笔记 认识HTTP协议 HTTP 基础[https://www.ji...

  • java基础总结

    1、HTTP和HTTPS区别 HTTPS是HTTP协议的安全版本,HTTP协议的数据传输是明文的,是不安全的,HT...

  • 面试官系列 - https 真的安全吗,可以抓包吗,如何防止抓包

    [TOC] 往期文章 Android 面试必备 - http 与 https 协议 Android 面试必备 - ...

  • HTTP协议与HTTPS协议

    协议是指计算机通信网络中两台计算机之间进行通信所必须共同遵守的规定或规则。 1、HTTP 协议 1.1、 什么是 ...

  • HTTPS协议改为HTTP协议

    tableview的数据源一般都是成员变量 iOS9为HTTPS协议,需要证书,证书不开放个人申请,所以我们需要将...

  • Http协议和Https协议

    Http网络协议 一、简介 超文本传输协议,基于TCP/IP协议来传输数据; 原理:客户端-服务端架构,客户通过U...

  • http协议和https协议

    概念 http协议的全称是超文本传输协议,是一个基于请求和响应的、无状态的、应用层的协议,常基于TCP/IP协议传...

  • Http, Https协议

    # Http, Https协议 * 参考资料 * [HTTP](https://github.com/CyC20...

  • 协议(HTTP HTTPS)

    目的: OSI 七层模型通过七个层次化的结构模型使不同的系统不同的网络之间实现可靠的通讯,因此其最主要的功能就是帮...

网友评论

      本文标题:Android http协议转换https协议 6.0以下版本

      本文链接:https://www.haomeiwen.com/subject/tdkgqqtx.html