现要求,客户端向服务端以httpclient的post方式发送“XML格式的字符串”,服务器接收字符串数据,解析之后返回“XML格式的字符串”给客户端。
String url="http://localhost:8080/smartHN/regist/regist.action?method=userReg";
HttpClient hc = new HttpClient();
PostMethod post = new PostMethod(url);
post.setRequestBody ("<xml><name>long</name><age>24</age><address>wuhan</address></xml>");
try {
int state = hc.executeMethod(post);
if(state!=HttpStatus.SC_OK){
System.out.println("远程访问失败!");
}
System.out.println(post.getResponseBodyAsString());//反馈结果
} catch (HttpException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}