简体   繁体   中英

Java: discrepancy between message sent from client and message received at server

I don't know how can they possibly be different. The discrepancy is that at the client there are more spaces than at the server, so I get this when I try to parse at the server: Parsing DOM - org.xml.sax.SAXParseException Here is the code, and the messages are included in the comments:

Element rootElement = document.createElement(MyServer.NEW_PLAYER_CONNECTION_REQUEST);
    Element participantTypeElement = document.createElement(MyServer.PARTICIPANT_TYPE);
    Text textParticipantType = document.createTextNode(participantType);
    participantTypeElement.appendChild(textParticipantType);
    rootElement.appendChild(participantTypeElement);
    document.appendChild(rootElement);
    StringWriter sw = new StringWriter();
    TransformerFactory tFactory = TransformerFactory.newInstance();
    Transformer transformer;
    try {
        transformer = tFactory.newTransformer();
        DOMSource source = new DOMSource(document);
        StreamResult result = new StreamResult(sw);
        transformer.transform(source, result);
    } catch (TransformerConfigurationException e) {
        e.printStackTrace();
    }
    catch (TransformerException t) {
        t.printStackTrace();
    }
    try {
        conn.setRequestMethod("POST");
    } catch (ProtocolException e) {
        e.printStackTrace();
    }
    conn.setRequestProperty("Content-Type", "text/xml");
    //conn.setRequestProperty("Content-Length", "" +  8);
    conn.setRequestProperty("Content-Language", "en-US");  

Just a suppose,but reading(more than conversion) between UTF-8 and other ASCii charsets can cause minor faults in character numerics reading/rendering through a stream. The charsets between the two points is likely the problem.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM