From: Carlos Date: 2004-12-27T13:33:42+09:00 Subject: Re: HTML and CSS validation Bil Kleb wrote: > http://www.htmlhelp.com/tools/validator/upload.html > http://validator.w3.org/file-upload.html > > because I'm reluctant to install W3's source due > to it's large dependency chain and I'm too stupid > to figure out how to automate the interaction > with these file upload interfaces. > > From looking at their form source and reading a bit > about file upload forms, I gather that I have to send > a form with enctype="multipart/form-data", but it > is unclear just how to do this. Your request should be something like this (not tested): # let's say that what you write to stdout goes to the server # ('validator-page' is the path that appears in the 'action' # attribute of the
separator = "----------------------86428764287643287642" print "POST /validator-page HTTP/1.1\r\n" # you first send a header for your request print "Host: www.example.org\r\n" # the server, probably www.htmlhelp.com print "User-Agent: RubyValidator/1.0 :)\r\n" print "Content-Type: multipart/form-data; boundary=", separator, "\r\n" print "\r\n" # and then goes every form field, prefixed by separator and a header print separator, "\r\n" print "Content-Disposition: form-data; name=\"fieldname\"\r\n" # the name in the form field print "Content-Type: text/plain; charset=UTF-8\r\n" # for almost every field type print "Content-Transfer-Encoding: 8 bit\r\n" print "\r\n" print "These are the contents of the text field.\r\n" # for a file upload, the headers change slightly print separator, "\r\n" print "Content-Disposition: form-data; name=\"fieldname\"" # the name in the form field print "; filename=\"file-name.html\"\r\n" # ..and in this case the filename print "Content-Type: application/octet-stream\r\n" # the content type also changes... # ...but I guess you can put "text/html; charset=..." as well print "Content-Transfer-Encoding: 8 bit\r\n" # or whatever print "\r\n" print your_file_in_a_string print "\r\n" # you finalize your request with the separator plus two dashes print separator, "--\r\n" A tip: create a simple webrick servlet that only outputs its request. Then copy any form you want to automate to your local machine, and change its "action" attribute to point to your servlet. Then you'll know exactly what you need to send. Good luck.