這是我使用的連接到URL的代碼,它的工作正常,但我想要字符串中的http請求,我想知道實際上發送到服務器的是什麼如何在java中打印http請求作爲字符串
HttpURLConnection conn = null;
try {
URL url = new URI(baseURL).toURL();
conn = (HttpURLConnection) url.openConnection();
conn.setRequestMethod("POST");
conn.setRequestProperty("User-Agent", "Mozilla/5.0");
conn.setRequestProperty("Content-Type",
"application/x-www-form-urlencoded");
conn.setRequestProperty("Content-Length", Integer.toString(builder.toString().length()));
conn.setConnectTimeout(10000);
conn.setReadTimeout(10000);
conn.setUseCaches(false);
OutputStream outputStream = new BufferedOutputStream(conn.getOutputStream());`
BufferedWriter writer = new BufferedWriter(
new OutputStreamWriter(outputStream, "UTF-8"));
writer.write(builder.toString());
writer.flush();
writer.close();
outputStream.close();
conn.connect();
requestStatusCode = conn.getResponseCode();
}
我想什麼是真正被髮送到服務器
是否要檢查使用的URL或所有http params? – NAIT
我想檢查用戶代理,主機和 – Ashwa
如何打印一個http請求作爲字符串,然後提供給我輸出 – Ashwa