當soap請求出現如下錯誤的時候:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soapenv:Header/>
<soapenv:Body>
<soapenv:Fault>
<faultcode>soapenv:Server.generalException</faultcode>
<faultstring>org.xml.sax.SAXParseException: The root element is required in a well-formed document. Message being parsed: </faultstring>
</soapenv:Fault>
</soapenv:Body>
</soapenv:Envelope>
是因爲soap的請求沒有明確寫出請求包的長度,使server端不能完整讀取請求包,server端便錯誤的認爲請求的xml文件不完整。
只要明確的寫上請求包得長度即可,java代碼如下:
out.println("Content-Length: 257");