[英]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:
差异是客户端上的空间比服务器上的空间多,因此当我尝试在服务器上进行解析时会得到此信息: 解析DOM-org.xml.sax.SAXParseException这是代码,消息包含在其中评论:
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. 只是一个假设,但是在UTF-8和其他ASCii字符集之间进行读取(而不是转换)可能会导致通过流读取/呈现字符数字时出现较小的错误。 The charsets between the two points is likely the problem.
两点之间的字符集可能是问题所在。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.