我在java中发出http post请求,我需要查看请求中发送的xml。 有没有办法在java中看到xml?请提供打印发送的请求xml的方法。在Java中如何提取通过java发送的Http Post请求中的xml?
示例代码:
public static void main(String[] args) {
// TODO Auto-generated method stub
HttpClient cl = new HttpClient();
PostMethod postMethod = new PostMethod("***URL***");
NameValuePair[] params = {
new NameValuePair("dealerId", "***sampleDealerId***"),
new NameValuePair("queryId", "***sampleQueryId***")
};
postMethod.setRequestBody(params);
cl.getParams().setAuthenticationPreemptive(true);
Credentials defaultCreds = new UsernamePasswordCredentials("***user***", "***password***");
cl.getState().setCredentials(AuthScope.ANY, defaultCreds);
try {
try {
cl.executeMethod(postMethod);
}
catch (IOException e) {
e.printStackTrace();
}
BufferedReader br;
try {
System.out.println(postMethod.getStatusCode());
System.out.println(postMethod.getStatusText());
br = new BufferedReader(new InputStreamReader(postMethod.getResponseBodyAsStream()),256);
String line;
char[] chars = new char[256];
while (br.read(chars) != -1) {
System.out.println(chars);
chars = new char[256];
}
}
catch (IOException e) {
e.printStackTrace();
}
}
finally {
postMethod.releaseConnection();
}
}
嘿,你可以请共享更多细节如何以及在Commons Logging Interface中设置日志参数的位置?还需要在程序中打印什么来获取请求xml? – Sapan 2014-09-01 08:17:24