importjava.io.BufferedReader;importjava.io.InputStreamReader;importjava.util.Date;importjava.util.HashMap;importjava.util.List;importorg.apache.commons.httpclient.HttpClient;importorg.apache.commons.httpclient.HttpStatus;importorg.apache.commons.httpclient.methods.PostMethod;importorg.apache.commons.httpclient.methods.RequestEntity;importorg.apache.commons.httpclient.methods.StringRequestEntity;public classTest {/***@paramargs*/
public static void main(String[] args) throwsException{//直接字符串拼接
StringBuffer sb = newStringBuffer();
sb.append("pengxwtestpengxwtest" +
"pengxwtestpengxwtest" +
"201" +
"23");//xml数据存储
String data =sb.toString();
String url= "接口地址";
HttpClient httpclient= newHttpClient();
PostMethod post= newPostMethod(url);
String info= null;try{
RequestEntity entity= new StringRequestEntity(data, "text/xml","iso-8859-1");
post.setRequestEntity(entity);
httpclient.executeMethod(post);int code =post.getStatusCode();if (code ==HttpStatus.SC_OK)
info= new String(post.getResponseBodyAsString()); //接口返回的信息
} catch(Exception ex) {
ex.printStackTrace();
}finally{
post.releaseConnection();
}
System.out.println(info);
}//读取xml文件
public classxmlTool(){
InputStreamReader read= new InputStreamReader (new FileInputStream("f://aa.xml"),"UTF-8");
StringBuffer sb= newStringBuffer();
BufferedReader br= newBufferedReader(read);
String row;while((row = br.readLine())!=null){
sb.append(row.trim());
}
String data=sb.toString();
String url= "http://localhost:9099/vtoss/cloudapi/rp_video_transcode_batch.do";
HttpClient httpclient= newHttpClient();
PostMethod post= newPostMethod(url);
String info= null;try{
RequestEntity entity= new StringRequestEntity(data, "text/xml","UTF-8");
post.setRequestEntity(entity);
httpclient.executeMethod(post);int code =post.getStatusCode();if (code ==HttpStatus.SC_OK)
info= newString(post.getResponseBodyAsString());
}catch(Exception ex) {
ex.printStackTrace();
}finally{
post.releaseConnection();
}
System.out.println(info);
}
}