SSL连接

时间:2013-06-10 15:24:02

标签: android ssl connection

我需要为Android应用程序进行SSL连接。我已经尝试了我找到的每个样本,但没有人在我的应用程序中工作。这是我第一次进行SLL连接而且我不确定我做得好还是坏,所以有人可以告诉我一些手册,指南,书籍或类似的地方,其中SSL连接是从零开始解释的谢谢。

修改 我需要的是一些学习如何管理SSL连接的指南,无论如何这是我正在使用的代码,我是从StackOverflow获得的。

其中: url是连接的网址 用户和密码是字符串

 DefaultHttpClient http = new DefaultHttpClient();
    SSLSocketFactory ssl =  (SSLSocketFactory)http.getConnectionManager().getSchemeRegistry().getScheme( "https" ).getSocketFactory(); 
    ssl.setHostnameVerifier( SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER );

    Credentials creds = new UsernamePasswordCredentials(username,password);
    http.getCredentialsProvider().setCredentials(new AuthScope(AuthScope.ANY_HOST, AuthScope.ANY_PORT), creds);


    HttpResponse res;

    try{
        HttpPost httpost = new HttpPost(url);
        httpost.setEntity(new StringEntity(request));
        res = http.execute(httpost);

        InputStream is = res.getEntity().getContent();
        BufferedInputStream bis = new BufferedInputStream(is);
        ByteArrayBuffer baf = new ByteArrayBuffer(50);
        int current = 0;
        while((current = bis.read()) != -1){
          baf.append((byte)current);
        }
        Log.d("resp","resp"+new String(baf.toByteArray()));
    }

    catch (ClientProtocolException e) {
       e.printStackTrace();
    } 
    catch (IOException e) {
       e.printStackTrace();
    }

事实上,我正在尝试做同样的事情 Android Ignoring HTTPS conexion

0 个答案:

没有答案