正在寻找通过window.XMLHttpRequest发送xml字符串的java等效程序

正在寻找通过window.XMLHttpRequest发送xml字符串的java等效程序,java,javascript,ajax,servlets,Java,Javascript,Ajax,Servlets,在JavaScript中,我们有以下实现: function sendRMSRequest(xmlString, url){ if(window.XMLHttpRequest){ xmlRequest = new XMLHttpRequest(); } xmlRequest.open("POST", url, false); xmlRequest.onreadystatechange = function() {processRequest()

在JavaScript中,我们有以下实现:

function sendRMSRequest(xmlString, url){

    if(window.XMLHttpRequest){
        xmlRequest = new XMLHttpRequest();
    }

    xmlRequest.open("POST", url, false);
    xmlRequest.onreadystatechange = function() {processRequest();};
    xmlRequest.send(xmlString);
}
xmlString具有以下字符串:

<TestRequest xmlns='http://???.???.????' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'></TestRequest>
任何帮助都将不胜感激

谢谢
Daniel

您能发布所有错误字符串吗?因为我正在处理客户端应用程序,所以我不想公开应用程序的任何信息。我可以告诉您,在这两个示例中,我发送的是相同的xml字符串。(JavaScript和Java)。在这一点上,我不太关心例外情况。我想知道如何从Java应用程序发布XML字符串。谢谢SAXParseException在哪里发生?您提供的代码根本不使用SAXAPI?它发生在服务器端,此时我无法访问源代码。
public static void main(String[] args) throws IOException {
    String endPoint = "http://????.????/service";


    String xml =  "<TestRequest xmlns='http://???.???.????' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'></TestRequest>";

    System.out.println(xml);

    URL url = new URL(endPoint);
    HttpURLConnection httpCon = (HttpURLConnection) url.openConnection();
    httpCon.setDoInput(true);
    httpCon.setDoOutput(true);
    Authenticator.setDefault(new MyAuthenticator());

    httpCon.setReadTimeout(0);
    httpCon.setConnectTimeout(0);
    httpCon.setRequestMethod("POST");
    httpCon.setRequestProperty("Content-Type", "text/plain"); 
    httpCon.setRequestProperty("charset", "utf-8");
    httpCon.setRequestProperty("", xml);


    PrintWriter pw = new PrintWriter(httpCon.getOutputStream());  

    pw.write(xml);
    pw.flush();
    pw.close();  

    System.out.println(httpCon.getResponseCode());
    System.out.println(httpCon.getResponseMessage());
    System.out.println(httpCon.getContentType());



    String returnString = null;
    StringBuffer sb = null;
    BufferedInputStream in;

    // set up httpConn code not included same as previous
    in = new BufferedInputStream(httpCon.getInputStream());  

    int x = 0;

    sb = new StringBuffer();

    while ((x = in.read()) != -1) {
        sb.append((char) x);
    }

    in.close();
    in = null;

    if (httpCon != null) {
        httpCon.disconnect();
    }

    returnString = sb.toString();   
    System.out.println("Return String = " + returnString);

}
org.xml.sax.SAXParseException: Premature end of file.