How to extract the xml sent in a Http Post request through java?



I am making a http post request in java and I need to see the xml which is sent in the request. Is there a way to see that xml in java ? Please provide the method to print the request xml sent.


Sample code in java :



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();
}

}

No comments:

Post a Comment