Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/http/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android Http到Https和SSL crt_Android_Http_Https_Ssl Certificate - Fatal编程技术网

Android Http到Https和SSL crt

Android Http到Https和SSL crt,android,http,https,ssl-certificate,Android,Http,Https,Ssl Certificate,我正在处理https post请求。 我成功地完成了http post请求,但我不知道如何使用https SSL crt更改它。 如何在项目中添加SSL crt以及如何将http转换为https。 我试过很多例子,但都不明白 我的http post请求代码是。。储蓄是我的自由 public class ServerCommunication implements Runnable, IServerCommunication { private static final String TAG

我正在处理https post请求。 我成功地完成了http post请求,但我不知道如何使用https SSL crt更改它。 如何在项目中添加SSL crt以及如何将http转换为https。 我试过很多例子,但都不明白

我的http post请求代码是。。储蓄是我的自由

 public class ServerCommunication implements Runnable, IServerCommunication {
 private static final String TAG = ServerCommunication.class.getSimpleName();

 private  String url;
 private  String userAgent;
 private  byte[] data;

 static
 {
        System.loadLibrary("saNative");
 }

private static void receiveBytestream(byte[] stream)
{
    saVersion.getInstance().onSecurePacketReceived(stream);
}

/**
 * Functions as a container to create other (meaningfuller) instances only
 */
public ServerCommunication()
{
    Log.d(TAG, "Note this class is deprecated");
}


private ServerCommunication(String _url, String _userAgent, byte[] _data)
{
    url = _url;
    userAgent = _userAgent;
    data = _data;
}

public void run()
{
    DefaultHttpClient httpclient = new DefaultHttpClient();


    if(url.equals(""))
    {
        Log.e(TAG, "URL is an empty string... aborting sending procedure");
        return;
    }

    // make URL     
    HttpPost httpost = new HttpPost(url);

    StringEntity se;
    try {
        se = new StringEntity(new String(data) + "\r\n");


        httpost.setEntity(se);
        httpost.setHeader("Accept", "application/json");
        httpost.setHeader("Content-Type", "application/json");


        // Get User Agent String
        httpost.setHeader("User-Agent", userAgent); // set string

    } catch (UnsupportedEncodingException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }


    try {

        HttpResponse response = httpclient.execute(httpost);


        InputStreamReader sr = new InputStreamReader(response.getEntity().getContent());    
        byte[] respContent = IOUtils.toByteArray(sr);           
        receiveBytestream(respContent); 
    } 
    catch (ClientProtocolException e) 
    {
        Log.e(TAG, "AS-Connection error: Probably Internet-Permission is not set in your manifest?");
        e.printStackTrace();

    } 
    catch (IOException e) 
    {
        Log.e(TAG, "AS-Connection error: Probably Internet-Permission is not set in your manifest?");
        e.printStackTrace();

    }
    finally
    {

    }
}    


@Override
public void sendSecurePacket(String _url, byte[] _data, String userAgent) {
    ServerCommunication sc = new ServerCommunication(_url, userAgent, _data);               
    Thread t = new Thread(sc);      
    t.start();  

}

}

前几天我也遇到了同样的问题,我已经在我的博客上发表了。希望它能对您有所帮助。

我使用了自己的证书。@user3555472很高兴能帮助您。Happy Codding:)虽然这可以回答问题,但最好在这里提供实际信息,而不仅仅是一个链接。