簡體   English   中英

如何檢查通過HttpsURLConnection發送的HTTP請求標頭?

[英]How to inspect the HTTP request headers sent through a HttpsURLConnection?

下面的簡單Java代碼有效。 有沒有一種簡單的方法來查找/檢查實際發送的HTTP 請求 (不是響應)標頭?

import java.net.URL;
import java.io.*;
import javax.net.ssl.HttpsURLConnection;

public class Test {
    public static void main(String[] args) throws Exception {
        String httpsURL = "https://api.gdax.com/products/BTC-USD/book?level=1";
        URL myurl = new URL(httpsURL);
        HttpsURLConnection con = (HttpsURLConnection) myurl.openConnection();
        InputStream ins = con.getInputStream();
        InputStreamReader isr = new InputStreamReader(ins);
        BufferedReader in = new BufferedReader(isr);

        String inputLine;

        while ((inputLine = in.readLine()) != null) {
            System.out.println(inputLine);
        }

        in.close();
    }
}

我認為您不能以編程方式做到這一點,可以在Eclipse中使用某種代理,例如TCP / IP監視器。 或為java啟用debbug選項,並添加以下選項:

-Djava.util.logging.config.file=logging.properties

並將以下屬性放入logging.properties(默認情況下在JRE_HOME \\ lib中)

sun.net.www.protocol.http.HttpsURLConnection.level = ALL

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM