从Java/JBoss查看原始HTTP POST的方法如下:
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.net.HttpURLConnection;
import java.net.URL;
public class Main {
public static void main(String[] args) throws Exception {
// 创建URL对象
URL url = new URL("http://example.com/api/endpoint");
// 打开连接
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
// 设置请求方法为POST
connection.setRequestMethod("POST");
// 设置请求头
connection.setRequestProperty("Content-Type", "application/json");
// 启用输出流,用于发送POST数据
connection.setDoOutput(true);
// 构造POST数据
String postData = "{\"key\": \"value\"}";
// 获取输出流并写入POST数据
OutputStream outputStream = connection.getOutputStream();
outputStream.write(postData.getBytes());
outputStream.flush();
outputStream.close();
// 获取响应码
int responseCode = connection.getResponseCode();
// 读取响应数据
BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream()));
String line;
StringBuilder response = new StringBuilder();
while ((line = reader.readLine()) != null) {
response.append(line);
}
reader.close();
// 输出原始HTTP POST请求和响应数据
System.out.println("Request:");
System.out.println(connection.getRequestMethod() + " " + url);
System.out.println(connection.getRequestProperty("Content-Type"));
System.out.println(postData);
System.out.println("Response:");
System.out.println(responseCode);
System.out.println(response.toString());
}
}
standalone.xml
。<subsystem xmlns="urn:jboss:domain:logging:3.0">
节点。<logger category="org.apache.http.wire">
节点,如果不存在,则添加以下配置:<logger category="org.apache.http.wire">
节点,如果不存在,则添加以下配置:以上是从Java/JBoss查看原始HTTP POST的方法,通过使用Java的网络编程库或配置JBoss的日志级别,可以获取到原始的HTTP POST请求和响应数据。
领取专属 10元无门槛券
手把手带您无忧上云