Correct value of parameter uploaded_file

Dear Sir or Madam,

I'm writing a http-webserver in Java which generates HTML-code and sends
it to the browser. This code isn't a complete HTML-side. It's just some
tags. The whole generated HTML-code has to be checked that it is XHTML
conform.
My idea of doing the check:
Generate a minimum HTML-page which is XHTML conform, put the generated
code into the body, and let it check via file upload. (The Java code is
posted at the end of this mail.)
I tried several URLs:
  http://validator.w3.org/check?uploaded_file
  http://validator.w3.org/check?uploaded_file=
  http://validator.w3.org/check?uploaded_file=1
  http://validator.w3.org/check?uploaded_file=test
  http://validator.w3.org/check?uploaded_file=Test.html
  http://validator.w3.org/check?uploaded_file='Test.html'
  http://validator.w3.org/check?uploaded_file="Test.html"
  (" was notated as \" when I put it into the Java String)
Each time I got the message:
1. Error
   Sorry, this type of URL scheme ("undefined") is not supported by this
service. Please check that you entered the URL correctly.

I looked for help in the internet for several hours, but I didn't know
where the mistake is. What do I have to write as value of uploaded_file?

Yours faithfully,
Daniel Janke


/**
  * Checks if <code>html</code> is correct XHTML.
  *
  * @param html
  * @return true iff the online validator sends all ok
  */
private boolean checkXHTML(String html) {
  boolean isValid = false;
  // validator can only check complete HTML-sides
  String side = "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>"
    + "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\"
\"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">"
    + "<html xmlns=\"http://www.w3.org/1999/xhtml\">"
    + "<head>"
    + "<meta http-equiv=\"Content-Type\" content=\"text/html;
charset=UTF-8\" />"
    + "<meta http-equiv=\"Content-Script-Type\"
content=\"text/javascript\" />"
    + "<meta http-equiv=\"Content-Style-Type\" content=\"text/css\" />" +
"<title></title>"
    + "</head>"
    + "<body>"
    + html //the HTML-code
    + "</body>" + "</html>";
  try {
    // create connection to the validator
    URL u = new URL("http://validator.w3.org/check?uploaded_file=test");
HttpURLConnection httpCon = (HttpURLConnection) u.openConnection();
httpCon.setDoOutput(true);
    //create boundary
    String boundary = "---------------------------";
    boundary+=Long.toString(new Random().nextLong(), 36);
    boundary+=Long.toString(new Random().nextLong(), 36);
    boundary+=Long.toString(new Random().nextLong(), 36);
    //set contentType and boundary
    httpCon.setRequestProperty("Content-Type",
      "multipart/form-data; boundary=" + boundary);
    //upload file
    OutputStream os = httpCon.getOutputStream();
    os.write(("--"+boundary+"\r\n").getBytes());
    os.write(("Content-Disposition: form-data; name=\"test\"; "
      +"filename=\"Test.html\"\r\n").getBytes());
    os.write(("Content-Type: text/html\r\n").getBytes());
    os.write(("\r\n").getBytes());
    os.write(side.getBytes());
    os.write(("\r\n").getBytes());
    os.write(("--"+boundary+"--\r\n").getBytes());
    os.flush();
    os.close();
    String header = httpCon.getHeaderField("X-W3C-Validator-Status").trim()
      .toLowerCase();
    // disconnect
    if (!header.equals("valid")) {
      // creates an file to see the error message
      writeReceived(httpCon.getInputStream(), httpCon);
    }
    httpCon.disconnect();
    System.out.println(header);
    isValid = header.equals("valid");
  } catch (MalformedURLException e) {
    e.printStackTrace();
  } catch (UnsupportedEncodingException e) {
    e.printStackTrace();
  } catch (IOException e) {
    e.printStackTrace();
  }
  return isValid;
}

Received on Wednesday, 12 August 2009 20:19:35 UTC