【问题标题】:Https request not working for android ApplicationHTTPS请求不适用于Android应用程序
【发布时间】:2015-09-27 09:10:25
【问题描述】:

当 HTTP 工作正常时,我的机器上没有为 Android 应用程序唤醒 Https 请求。 我做了很多护目镜,但找不到成功。

public static String requestWithPostMethod(String url, String jsonData) * 抛出 * 客户端协议异常,IOException */ { //HttpURLConnection urlConnection;

    String result = null;
    try {
        // Connect

        URL newurl = new URL(url);
        HttpURLConnection urlConnection = (HttpURLConnection) newurl.openConnection();
    //  urlConnection = createConnection(url);
        urlConnection.setRequestMethod("POST");
        urlConnection
                .setRequestProperty("Content-Type", "application/json");
        urlConnection.setRequestProperty("Accept", "application/json");

        urlConnection.connect(); //here it return null exception

        // Write
        OutputStream outputStream = urlConnection.getOutputStream();
        BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(
                outputStream, "UTF-8"));
        writer.write(jsonData);
        writer.close();
        outputStream.close();

        // Read
        BufferedReader bufferedReader = new BufferedReader(
                new InputStreamReader(urlConnection.getInputStream(),
                        "UTF-8"));

        String line = null;
        StringBuilder sb = new StringBuilder();

        while ((line = bufferedReader.readLine()) != null) {
            sb.append(line);
        }

        bufferedReader.close();

        // {"success":true,"result":[],"error":"","error_key":"email_validation_code"}

        result = sb.toString();

    } catch (UnsupportedEncodingException e) {
        if (e != null) {
            e.printStackTrace();
        }
    } catch (IOException e) {
        if (e != null) {
            e.printStackTrace();
        }
    }
    return result;
}

【问题讨论】:

    标签: https


    【解决方案1】:

    这可能是服务器证书的问题。

    【讨论】:

      猜你喜欢
      • 2016-10-19
      • 2020-11-20
      • 2016-07-16
      • 1970-01-01
      • 1970-01-01
      • 2017-12-23
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多