W3C home > Mailing lists > Public > www-validator@w3.org > August 2012

Errors Uploading the File in W3C Validator

From: Harshit Oberoi <oberoi.harshit@gmail.com>
Date: Wed, 29 Aug 2012 11:24:50 +0530
Message-ID: <CAKQcKjo1qmuCp9CDVRDuGnpivDu+OE-dkgiFWWzqQ0atPbbq8A@mail.gmail.com>
To: www-validator@w3.org
Hi,

I am trying to Upload my file at W3C validator for validation but my code
is working for small size file but it gives (500) Internal Server error for
large size HTML File .

Pasting my code below , is there any change I need to made.

Code :


static void Main(string[] args)

{

string urlOfTool = "http://validator.w3.org/check";

string fileToValidate = @"C:\Users\v-harsho\Desktop\Code Snippet\msn.htm";

ValidateFile(urlOfTool, fileToValidate);

}

public static void ValidateFile(string urlOfTool, string fileToValidate)

{

string boundary = "----------------------------" +DateTime
.Now.Ticks.ToString("x");

string data = "--" + boundary + "\r\n";

data += "Content-Disposition: form-data; name=\"uploaded_file\";
filename=\"" + fileToValidate + "\"\r\n";

data += "Content-Type: text/html \r\n";

byte[] dataByte = System.Text.Encoding.UTF8.GetBytes(data);

byte[] fileByte = System.IO.File.ReadAllBytes(fileToValidate);

byte[] end = System.Text.Encoding.UTF8.GetBytes("\r\n--" +boundary +
"--\r\n");

System.Net.ServicePointManager.Expect100Continue = false;

HttpWebRequest httpWebRequest =(HttpWebRequest)WebRequest.Create(urlOfTool);

httpWebRequest.Headers.Add("Accept-Encoding", "gzip, deflate");

httpWebRequest.Accept ="text/html, application/xhtml+xml, */*";

httpWebRequest.Referer = "http://validator.w3.org/";

httpWebRequest.Headers.Add("Pragma","no-cache");

//httpWebRequest.ContentType=

httpWebRequest.Headers.Add("Accept-Language","en-US");

httpWebRequest.UserAgent = "Mozilla/5.0 (compatible; MSIE 9.0; Windows NT
6.1; Trident/5.0)";

httpWebRequest.Method = "POST";

httpWebRequest.ContentType = "multipart/form-data; boundary=" +boundary;

httpWebRequest.ContentLength =dataByte.Length + fileByte.Length+ end.Length;

httpWebRequest.KeepAlive = true;

httpWebRequest.Credentials = System.Net.CredentialCache.DefaultCredentials;

Stream requestStream = httpWebRequest.GetRequestStream();

requestStream.Write(dataByte, 0, dataByte.Length);

requestStream.Write(fileByte, 0, fileByte.Length);

requestStream.Write(end, 0, end.Length);

requestStream.Flush();

requestStream.Close();

WebResponse webResponse = httpWebRequest.GetResponse(); // this is the
location i'm getting the error.

StreamReader reader = new StreamReader(webResponse.GetResponseStream());

string temp = reader.ReadToEnd();

Console.WriteLine(temp);

System.IO.File.WriteAllText("test1.html", temp);

Console.ReadLine();

webResponse.Close();

}



Thanks

Harshit
Received on Wednesday, 29 August 2012 05:55:23 GMT

This archive was generated by hypermail 2.2.0+W3C-0.50 : Wednesday, 29 August 2012 05:55:30 GMT