账号密码登录
微信安全登录
微信扫描二维码登录

登录后绑定QQ、微信即可实现信息互通

手机验证码登录
找回密码返回
邮箱找回 手机找回
注册账号返回
其他登录方式
分享
  • 收藏
    X
    有什么办法可以看到我和服务器建立https连接时传输的信息?
    39
    0

    我想问的是 客户端和服务器建立Https 连接时传输的内容,这样对于我理解Https建立过程加深印象。

    我应该怎么做才能看到 Client HelloServer Hello 还有一些类似Pre-master Secret 以及 Finish等建立连接时需要传输的内容呢?

    就像当初我看Http 的时候,通过抓包,看到每个请求报文和响应报文,极大的帮助了我理解Http 是什么,所以我也想通过这样的方法来加深理解Https

    0
    打赏
    收藏
    点击回答
        全部回答
    • 0
    • 叶渊晦 普通会员 1楼

      在Java中,你可以使用SSL连接的参数来查看服务器发送给你的信息。以下是一个示例:

      ```java URL url = new URL("http://example.com"); try { HttpURLConnection connection = (HttpURLConnection) url.openConnection(); connection.setRequestProperty("Upgrade-Insecure-Requests", "1"); connection.setRequestProperty("Connection", "Upgrade"); connection.setRequestProperty("Content-Type", "application/json"); connection.setRequestProperty("Sec-WebSocket-Extensions", "bar");

      // Get the WebSocket Upgrade request header
      BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream()));
      String inputLine;
      StringBuffer response = new StringBuffer();
      
      while ((inputLine = in.readLine()) != null) {
          response.append(inputLine);
      }
      
      in.close();
      
      // Get the WebSocket Upgrade response header
      int statusLine = connection.getResponseCode();
      if (statusLine == HttpURLConnection.HTTP_OK) {
          String UpgradeResponse = connection.getResponseMessage();
          System.out.println("Upgrade Response: " + UpgradeResponse);
      }
      

      } catch (Exception e) { e.printStackTrace(); } ```

      在这个示例中,我们首先创建了一个URL对象,然后使用这个URL创建了一个HttpURLConnection对象。然后,我们设置了一些HTTP头,包括"Upgrade-Insecure-Requests","Connection"和"Content-Type"。最后,我们发送了一个Upgrade请求到服务器,并获取了服务器的响应。

      然后,我们读取服务器的响应,并从中获取了"Upgrade Response"头。如果这个头是一个有效的响应,我们就打印出来。

    更多回答
    扫一扫访问手机版
    • 回到顶部
    • 回到顶部