【问题标题】:javax.net.ssl.SSLException: Unable to parse TLS packet header in urlconnection.connect()javax.net.ssl.SSLException:无法解析 urlconnection.connect() 中的 TLS 数据包标头
【发布时间】:2021-08-19 11:12:14
【问题描述】:
URL url = new URL("https://IP:8006/Calculator/product");
        HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection();
        urlConnection.setRequestMethod("GET");
        urlConnection.connect();

在 url connect 上的 adroid-studio 中获取以下异常。请帮我解决这个问题

【问题讨论】:

    标签: android-studio httprequest


    【解决方案1】:

    您有两种方法可以解决您的问题:

    1. 使用 http 而不是 https。因此,使用的 URL 将是:"http://IP:8006/Calculator/product"
    2. 将 http 连接设置为 https,例如使用 HttpsURLConnection 进行 https 通信。

    【讨论】:

    • 在尝试以上两种方式时仍然收到相同的错误。还尝试将代码更改为 mRequestQueue = Volley.newRequestQueue(this); mStringRequest = new StringRequest(Request.Method.GET, url, new Response.Listener() {@Override public void onResponse(String response) {System.out.println(response);} }, new Response.ErrorListener( ) {@Override public void onErrorResponse(VolleyError error) {System.out.println(error.toString()); }}); mRequestQueue.add(mStringRequest);但该代码适用于其他 api。
    • 我无法仅连接到本地计算机上运行的 api。 P.S IP地址是我的android设备和本地机器都连接的一个
    • 您确定 HTTPS 运行良好吗?比如证书无效之类的
    • 是的,其他 https 请求在上面的代码中运行良好。只有我在本地机器 servlet 中开发的 api 不起作用并以图像形式返回消息
    • 你尝试过类似 postman 的东西吗?查看是否是您的 API 造成了问题
    猜你喜欢
    • 2021-07-25
    • 1970-01-01
    • 1970-01-01
    • 2021-01-30
    • 2020-06-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多