import java.io.*;importjava.net.HttpURLConnection;importjava.net.MalformedURLException;importjava.net.URL;importjava.net.URLConnection;public classUrlTest {voidtestPost(String urlStr) {try{
URL url= newURL(urlStr);
URLConnection con=url.openConnection();
con.setDoOutput(true);
con.setRequestProperty("Pragma:", "no-cache");
con.setRequestProperty("Cache-Control", "no-cache");
con.setRequestProperty("Content-Type", "text/xml;charset=gbk");
OutputStreamWriter out= newOutputStreamWriter(con.getOutputStream());
out.write(new String(getXmlInfo().getBytes("gbk")));
out.flush();
out.close();
BufferedReader br= new BufferedReader(newInputStreamReader(con.getInputStream()));
String msg= "";while ((msg = br.readLine()) != null) {
System.out.println(msg);
}
}catch(MalformedURLException e) {
e.printStackTrace();
}catch(IOException e) {
e.printStackTrace();
}
}privateString getXmlInfo() {
String body= "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>" +
"" +
"
" +" 666666" +
" V010" +
" shandong_gd" +
" " +
"
" +" " +
" " +
" 1" +
" " +
" BMW" +
" " +
" " +
"";returnbody;
}public static voidmain(String[] args) {
String url= "需要输入对应的接口地址";newUrlTest().testPost(url);
}
}