一部のXMLをSOAPリクエストとして送信していますが、そのXMLに文字&
またはが含まれている<
と、空の応答が返されます。関連するコードは次のとおりです。
String myXml = "<?xml version=\"1.0\" encoding=\"utf-8\"?>" +
"<soap12:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:soap12=\"http://www.w3.org/2003/05/soap-envelope\">" +
"<soap12:Body>" +
"[XML THAT DOESN'T WORK WITH '&' AND '<']" +
"</soap12:Body>" +
"</soap12:Envelope>";
HttpPost httpPost = new HttpPost("http://website.com");
StringEntity stringEntity = new StringEntity(myXml, HTTP.UTF_8);
stringEntity.setContentType("text/xml");
httpPost.setHeader("Content-Type", "application/soap+xml;charset=UTF-8)";
httpPost.setEntity(stringEntity);
HttpClient httpClient = new DefaultHttpClient();
BasicHttpResponse httpResponse = (BasicHttpResponse) httpClient.execute(httpPost);
HttpEntity httpEntity = httpResponse.getEntity();
InputStream inputStream = responseEntity.getContent();
//Checking inputStream here reveals that it is empty (not null) when xml has '&' or '<'
これらの事前定義されたエンティティが原因である可能性があると思いましたが、試してみた他のすべての特殊文字は問題を引き起こしませんでした。
これがなぜであるか、そしてどうすればそれを修正することができるか知っていますか(との特定のケースをキャッチする以外に&
)<
?
私はするための提案された解決策を見つけました
httpPost.setEntity(new UrlEncodedFormEntity(List<NameValuePair>, String encoding))
しかし、私はsを持っていませんNameValuePair
、ただStringEntity
。