I have a Play web app that makes an HTTP request to a server.
The request goes well: I get a response with an 200 status code and Content-type = "application/xml".
If I print to stdout the response body, I see a well-formed Xml doc.
However, if I try to create an org.w3c.dom.XML document from the response using WSResponse.asXml(), the method returns an empty document.
These are the relevant portions of my code:
private WSResponse sendPostRequest(String url, String body) {
WSRequest request = WS.url(url);
request.setHeader("Content-type", "application/x-www-form-urlencoded");
return request.post(body).get(5000L);
}
And:
public Result requestDefaultImport() {
String url = "some_url";
String body = "some_body";
WSResponse response = sendPostRequest(url, body);
System.out.println(response.getBody()); //prints well-formed Xml
Document xmld = response.asXml();
System.out.println(xmld); //prints: #[null document]
return ok();
}
What am I doing wrong?