HttpURLConnection 請求webservice出現錯誤
出現錯誤:
伺服器報錯500
返回資訊:no SOAPAction header!
<?xml version="1.0" encoding="utf-8"?><soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soapenv:Body>
<soapenv:Fault>
<faultcode xmlns:ns1="http://xml.apache.org/axis/">ns1:Client.NoSOAPAction</faultcode>
<faultstring>no SOAPAction header!</faultstring>
<detail>
<ns2:hostname xmlns:ns2="http://xml.apache.org/axis/">test01</ns2:hostname>
</detail>
</soapenv:Fault>
</soapenv:Body>
</soapenv:Envelope>
解決方案:在請求端,加上一個請求頭
openConnection.setRequestProperty("SOAPAction", "\"\"");或者
openConnection.setRequestProperty("SOAPAction", "");
參考另一篇博文:http://blog.csdn.net/wxyong3/article/details/38727503