// create a WebResource to access the given url
WebResource resource = Client.create().resource(url);
// prepare form data for posting
FormDataMultiPart form = new FormDataMultiPart();
// set the output format to soap12
// triggers the various outputs formats of the validator. If unset, the usual Web format will be sent.
// If set to soap12,
// the SOAP1.2 interface will be triggered. See the SOAP 1.2 response format description at
// http://validator.w3.org/docs/api.html#requestformat
form.field("output", "soap12");
// make sure Unicode 0x0 chars are removed from html (if any)
// see https://github.com/WolfgangFahl/w3cValidator/issues/1
Pattern pattern = Pattern.compile("[\\000]*");
Matcher matcher = pattern.matcher(html);
if (matcher.find()) {
html = matcher.replaceAll("");
}
// The document to validate, POSTed as multipart/form-data
FormDataBodyPart fdp = new FormDataBodyPart("uploaded_file",
IOUtils.toInputStream(html),
// new FileInputStream(tmpHtml),
MediaType.APPLICATION_OCTET_STREAM_TYPE);
// attach the inputstream as upload info to the form
form.bodyPart(fdp);
// now post the form via the Internet/Intranet
ClientResponse response = resource.type(MediaType.MULTIPART_FORM_DATA)
.post(ClientResponse.class, form);
// in debug mode show the response status