[imps] using the validator.nu API

Michael[tm] Smith mike at w3.org
Sun Dec 8 20:52:04 PST 2013

WebDevTutorials Support <support at webdevtutorials.net>, 2013-12-03 22:54 +0100:

> 		var xmlhttp = new XMLHttpRequest();
>                 xmlhttp.onreadystatechange = function() {
>                     if (xmlhttp.readyState == 4) {
>                         alert(xmlhttp.responseText);
>                         document.getElementById("responseWindow").src = "data:text/html;charset=utf-8," + xmlhttp.responseText;
>                     }
>                 }
>                 xmlhttp.open("POST", "http://validator.nu", true);

You need to put the "laxtype" and "parser" query parameters in the URL:

  xmlhttp.open("POST", "http://localhost:8888/?laxtype=yes&parser=html5", true)

>                 xmlhttp.setRequestHeader("Content-type", "multipart/form-data; boundary=doNotIncludeXadovAUvAvlBryUDSk5ZcdipW1fm8v79qYnXYmDG");

Don't use the setRequestHeader method for this case. You don't need it. If
you don't use it, the validator will just end up seeing the content as
text/plain -- but since you're also sending the laxtype=yes parameter, the
validator will ignore the content type and treat it as text/html.

Also you shouldn't be trying to format the entity body as multipart/form-data.

>                 xmlhttp.send("laxtype=yes&parser=html5&content=" + editor.getValue());

Don't put the query parameters in the entity body. The entity body should
just be the contents of the document you want to check. That is, the entity
body you send should start with "<!doctype html>". So assuming that's what
you get back from editor.getValue(), then just do:


> Unfortunately, this isn’t working. The server sends a response, but it says:
> Info: The Content-Type was application/octet-stream. Using the XML parser (not resolving external entities).
> Fatal Error: Empty document, with no root element.

I think the validator backend was failing to parse your editor.getValue()
contents as multipart/form-data because you were prepending
"laxtype=yes&parser=html5&content=" to the entity body, and if you're going
to send multipart/form-data, the data should instead just be formatted to
start with "--doNotIncludeXadovAUvAvlBryUDSk5ZcdipW1fm8v79qYnXYmDG", and
then probably 'Content-Disposition: form-data; name="content"', followed by
the contents of the document you want to have checked, and then

But if you're using POST with the validator, you really don't need to be
trying to send the data as multipart/form-data to begin with. Instead send
just the normal document contents as the data (the entity body).


Michael[tm] Smith http://people.w3.org/mike

More information about the Implementors mailing list