Solved

How to Post to a website and receive the result ?

Posted on 2004-09-22
22
1,719 Views
Last Modified: 2010-04-05
Hello,

i'm writing a css editor and there is an option in which the user can
validate his css file, so i want to post the css file to the w3c
validator:
http://jigsaw.w3.org/css-validator/

the site give me 3 options to validate the css,
1.either by direct input, this one failed because of the limit of ie
address
bar(2056 char) so i can't send the whole file in the url
2.or by uploading the file to my server and then posting its url,
which is
not practical, cause anyone using my program will have to upload a
file to
my server .
3.my last choice is by uploading the file to the w3c,i think this is my
only and good choice, but don't how to automatically post the css file using
indy or webbrowser or http controls. so anyone here could show how to post the file to the w3c validator and receive the results?

Here is again the site of the w3c validator http://jigsaw.w3.org/css-validator/

Thanks
Yehia
0
Comment
Question by:yehiaeg
  • 13
  • 8
22 Comments
 
LVL 12

Expert Comment

by:Ivanov_G
ID: 12128117
procedure TForm1.Button1Click(Sender: TObject);
var
  Params: TStringList;
begin
  Params := TStringList.Create;
  try
    begin
      Params.Add('text=' + Memo1.Lines.Text);
      Memo2.Lines.Text := IdHTTP1.Post('http://jigsaw.w3.org/css-validator/', Params);
    end;
  finally
    Params.Free;
  end;
end;
0
 
LVL 12

Expert Comment

by:Ivanov_G
ID: 12128257
sorry, in my prevous post the code is not good. here is a good one. But you receive a HTML file, so you should parse it fo find the result, or display it in TWebBrowser

procedure TForm1.Button1Click(Sender: TObject);
var
  Params   : TStringList;
  url      : String;
begin
  url := 'http://jigsaw.w3.org/css-validator/validator?text=&usermedium=all';
  Params := TStringList.Create;
  try
    begin
      Params.Add('text=' + Memo1.Lines.Text);
      Memo2.Lines.Text := IdHTTP1.Post(url, Params);
    end;
  finally
    Params.Free;
  end;
end;
0
 

Author Comment

by:yehiaeg
ID: 12128456
an  error occures?

<h2>Target: No file</h2>
<div class="error">
<p>I/O Error:
You have send an invalid request.
</p></div>
0
 
LVL 12

Expert Comment

by:Ivanov_G
ID: 12128894
Yep... I saw it. The problems comes because the CSS text is sent via GET .... which in my opinion sucks, but ...

I working on a solution...
0
 
LVL 12

Accepted Solution

by:
Ivanov_G earned 250 total points
ID: 12128985
uses idURI;

procedure TForm1.Button1Click(Sender: TObject);
var
  url      : String;
begin
  url := 'http://jigsaw.w3.org/css-validator/validator?text=';
  try
    url := url + TidURI.ParamsEncode(Memo1.Lines.Text);
    url := url + '&usermedium=all';
    Memo2.Lines.Text := IdHTTP1.Get(url);
  except
    MessageDlg('Connection problem!', mtError, [mbOK], 0);
    Exit;
  end;
end;
0
 
LVL 4

Expert Comment

by:tobjectpascal
ID: 12130076
I see what's going on

0000  50 4F 53 54 20 2F 63 73 73 2D 76 61 6C 69 64 61    POST /css-valida
0010  74 6F 72 2F 76 61 6C 69 64 61 74 6F 72 20 48 54    tor/validator HT
0020  54 50 2F 31 2E 31 0D 0A 41 63 63 65 70 74 3A 20    TP/1.1..Accept:
0030  69 6D 61 67 65 2F 67 69 66 2C 20 69 6D 61 67 65    image/gif, image
0040  2F 78 2D 78 62 69 74 6D 61 70 2C 20 69 6D 61 67    /x-xbitmap, imag
0050  65 2F 6A 70 65 67 2C 20 69 6D 61 67 65 2F 70 6A    e/jpeg, image/pj
0060  70 65 67 2C 20 61 70 70 6C 69 63 61 74 69 6F 6E    peg, application
0070  2F 78 2D 73 68 6F 63 6B 77 61 76 65 2D 66 6C 61    /x-shockwave-fla
0080  73 68 2C 20 61 70 70 6C 69 63 61 74 69 6F 6E 2F    sh, application/
0090  76 6E 64 2E 6D 73 2D 70 6F 77 65 72 70 6F 69 6E    vnd.ms-powerpoin
00A0  74 2C 20 61 70 70 6C 69 63 61 74 69 6F 6E 2F 6D    t, application/m
00B0  73 77 6F 72 64 2C 20 2A 2F 2A 0D 0A 52 65 66 65    sword, */*..Refe
00C0  72 65 72 3A 20 68 74 74 70 3A 2F 2F 6A 69 67 73    rer: http://jigs
00D0  61 77 2E 77 33 2E 6F 72 67 2F 63 73 73 2D 76 61    aw.w3.org/css-va
00E0  6C 69 64 61 74 6F 72 2F 0D 0A 41 63 63 65 70 74    lidator/..Accept
00F0  2D 4C 61 6E 67 75 61 67 65 3A 20 65 6E 2D 75 73    -Language: en-us
0100  0D 0A 43 6F 6E 74 65 6E 74 2D 54 79 70 65 3A 20    ..Content-Type:
0110  6D 75 6C 74 69 70 61 72 74 2F 66 6F 72 6D 2D 64    multipart/form-d
0120  61 74 61 3B 20 62 6F 75 6E 64 61 72 79 3D 2D 2D    ata; boundary=--
0130  2D 2D 2D 2D 2D 2D 2D 2D 2D 2D 2D 2D 2D 2D 2D 2D    ----------------
0140  2D 2D 2D 2D 2D 2D 2D 2D 2D 37 64 34 31 35 36 31    ---------7d41561
0150  65 31 37 30 34 31 36 0D 0A 41 63 63 65 70 74 2D    e170416..Accept-
0160  45 6E 63 6F 64 69 6E 67 3A 20 67 7A 69 70 2C 20    Encoding: gzip,
0170  64 65 66 6C 61 74 65 0D 0A 55 73 65 72 2D 41 67    deflate..User-Ag
0180  65 6E 74 3A 20 4D 6F 7A 69 6C 6C 61 2F 34 2E 30    ent: Mozilla/4.0
0190  20 28 63 6F 6D 70 61 74 69 62 6C 65 3B 20 4D 53     (compatible; MS
01A0  49 45 20 36 2E 30 3B 20 57 69 6E 64 6F 77 73 20    IE 6.0; Windows
01B0  4E 54 20 35 2E 30 29 0D 0A 48 6F 73 74 3A 20 6A    NT 5.0)..Host: j
01C0  69 67 73 61 77 2E 77 33 2E 6F 72 67 0D 0A 43 6F    igsaw.w3.org..Co
01D0  6E 74 65 6E 74 2D 4C 65 6E 67 74 68 3A 20 33 33    ntent-Length: 33
01E0  34 0D 0A 43 6F 6E 6E 65 63 74 69 6F 6E 3A 20 4B    4..Connection: K
01F0  65 65 70 2D 41 6C 69 76 65 0D 0A 43 61 63 68 65    eep-Alive..Cache
0200  2D 43 6F 6E 74 72 6F 6C 3A 20 6E 6F 2D 63 61 63    -Control: no-cac
0210  68 65 0D 0A 0D 0A                                  he....

4  Hide  Hide  334  Send  
0000  2D 2D 2D 2D 2D 2D 2D 2D 2D 2D 2D 2D 2D 2D 2D 2D    ----------------
0010  2D 2D 2D 2D 2D 2D 2D 2D 2D 2D 2D 2D 2D 37 64 34    -------------7d4
0020  31 35 36 31 65 31 37 30 34 31 36 0D 0A 43 6F 6E    1561e170416..Con
0030  74 65 6E 74 2D 44 69 73 70 6F 73 69 74 69 6F 6E    tent-Disposition
0040  3A 20 66 6F 72 6D 2D 64 61 74 61 3B 20 6E 61 6D    : form-data; nam
0050  65 3D 22 66 69 6C 65 22 3B 20 66 69 6C 65 6E 61    e="file"; filena
0060  6D 65 3D 22 43 3A 5C 79 6D 6C 69 74 65 62 75 67    me="C:\ymlitebug
0070  73 2E 74 78 74 22 0D 0A 43 6F 6E 74 65 6E 74 2D    s.txt"..Content-
0080  54 79 70 65 3A 20 74 65 78 74 2F 70 6C 61 69 6E    Type: text/plain
0090  0D 0A 0D 0A 20 70 72 6F 74 3A 79 63 68 74 0D 0A    .... prot:ycht..
00A0  20 66 69 78 20 70 6D 2C 20 68 6F 72 69 7A 6F 6E     fix pm, horizon
00B0  74 61 6C 0D 0A 20 0D 0A 2D 2D 2D 2D 2D 2D 2D 2D    tal.. ..--------
00C0  2D 2D 2D 2D 2D 2D 2D 2D 2D 2D 2D 2D 2D 2D 2D 2D    ----------------
00D0  2D 2D 2D 2D 2D 37 64 34 31 35 36 31 65 31 37 30    -----7d41561e170
00E0  34 31 36 0D 0A 43 6F 6E 74 65 6E 74 2D 44 69 73    416..Content-Dis
00F0  70 6F 73 69 74 69 6F 6E 3A 20 66 6F 72 6D 2D 64    position: form-d
0100  61 74 61 3B 20 6E 61 6D 65 3D 22 75 73 65 72 6D    ata; name="userm
0110  65 64 69 75 6D 22 0D 0A 0D 0A 61 6C 6C 0D 0A 2D    edium"....all..-
0120  2D 2D 2D 2D 2D 2D 2D 2D 2D 2D 2D 2D 2D 2D 2D 2D    ----------------
0130  2D 2D 2D 2D 2D 2D 2D 2D 2D 2D 2D 2D 37 64 34 31    ------------7d41
0140  35 36 31 65 31 37 30 34 31 36 2D 2D 0D 0A          561e170416--..


how big are the files you plan on checking?
0
 

Author Comment

by:yehiaeg
ID: 12131635
not limited, it's the user who edit the css files, so it could be 2 or 2000 lines
0
 

Author Comment

by:yehiaeg
ID: 12131711
for Ivanov_G, it worked like a champ, but is there any other way to do this without using the indy controls cause it added + 150 kb to my exe, there is some controls in the internet componenets like the webdispatcher, could they be useful in anyway ?
0
 
LVL 12

Expert Comment

by:Ivanov_G
ID: 12131769
well, probably there is another way, but in any case it is more time consuming.

1) via Win API... - more work and troubles

2) using TWebBrowser - this will add again more KB to your exe...

BTW TidURI component save you a lot of work for the CSS encoding - it conver the CSS to suitable GET parameter encoding #13 to %0D, etc... So in my opinion this is the fastest and least time consuming method...
0
 

Author Comment

by:yehiaeg
ID: 12131799
you're right , i'll keep "uses idURI" to convert the css to the uri format, but not sure about the  IdHTTP, it appears pretty advanced and all i used is the get method, i mean i don't need the advanced stuff,
And i've already the TWebBrowser in my project, so how could i use it to send the css file as u did with the indy?
0
 
LVL 12

Expert Comment

by:Ivanov_G
ID: 12131805
another way - if it is not a problem, you can make the validation in a separate DLL which will carry this 150 KB out of your EXE file, but ... it means one more file for deployment ...
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 12

Expert Comment

by:Ivanov_G
ID: 12131818
here it is without Indy Components:

function ParamsEncode(const ASrc: string): string;
var
  i: Integer;
begin
  Result := '';    {Do not Localize}
  for i := 1 to Length(ASrc) do begin
    if ASrc[i] = ' ' then begin    {do not localize}
      Result := Result + '+';    {do not localize}
    end else if NOT (ASrc[i] in ['A'..'Z', 'a'..'z', '0'..'9']) then begin {do not localize}
      Result := Result + '%' + IntToHex(Ord(ASrc[i]), 2);  {do not localize}
    end else begin
      Result := Result + ASrc[i];
    end;
  end;
end;

procedure TForm1.Button1Click(Sender: TObject);
var
  url    : String;
begin
  url := 'http://jigsaw.w3.org/css-validator/validator?text=';
  url := url + ParamsEncode(Memo1.Lines.Text);
  WebBrowser1.Navigate(url);
end;
0
 

Author Comment

by:yehiaeg
ID: 12131902
it seems that this code only takes the first 2056 or something from the css file as if i was putting it in the addressbar, someone told me this:
"this seems to be a internal IE limitation. A similar effect is
setting a lengthy URL via script code, which will fail if the URL is that
long. So I'm afraid that even the instantiation of a IE COM object and
Navigate() to this URL may fail, but you can try it."

so anyother solution? can the TwebDispatcher be useful here?
0
 
LVL 12

Expert Comment

by:Ivanov_G
ID: 12132171
yes, this is a limit, but this is the URL: http://jigsaw.w3.org/css-validator/validator

the CSS is GET parameter and I don't think the parameters are limited. If W3 consortium made it with GET parameter, I am willing to beleive them ... :)))
0
 
LVL 12

Expert Comment

by:Ivanov_G
ID: 12132235
Is there a limit on the length of the URL string?
http://help.netscape.com/kb/consumer/19971015-8.html

What is the maximum length of a URL string?
http://www.faqts.com/knowledge_base/view.phtml/aid/329

Maximum URL Length Is 2,083 Characters in Internet Explorer
http://support.microsoft.com/?id=208427
0
 
LVL 12

Expert Comment

by:Ivanov_G
ID: 12132253
The last link will proove that Microsoft sucks...

If you are using the GET method, you are limited to a maximum of 2,048 characters (minus the number of characters in the actual path, of course).

POST, however, is not limited by the size of the URL for submitting name/value pairs, because they are transferred in the header and not the URL.

****************************************************************************
*  RFC 2616, Hypertext Transfer Protocol -- HTTP/1.1, does not specify any requirement for URL length.  *
****************************************************************************
0
 

Author Comment

by:yehiaeg
ID: 12132561
>>yes, this is a limit, but this is the URL: http://jigsaw.w3.org/css-validator/validator
>>the CSS is GET parameter and I don't think the parameters are limited. If W3 consortium made
>>it with GET parameter, I am willing to beleive them ... :)))

i don't know about this but i tried to pass a large css file and the result was half of it,
anyway it seems that i'll go with indy idHTTP, still is there any other way, i thought TWebDispatcher could do something like this?
0
 
LVL 12

Expert Comment

by:Ivanov_G
ID: 12132763
I think Indy is better ... I am not sure about the Dispatcher ... but probably it is not better tha TidHTTP ...
0
 

Author Comment

by:yehiaeg
ID: 12132887
sure? cause the dispatcher adds only 15 kb to my exe, anyway you can look up how can i use it?
0
 
LVL 12

Expert Comment

by:Ivanov_G
ID: 12133000
Description (from Delphi Help)
Use TWebDispatcher to convert an ordinary data module to a Web module...

I am not sure this is what you are looking for...

  TCustomWebDispatcher = class(TDataModule, IWebRequestHandler, IWebDispatchActions, IWebDispatcherAccess,
    IMultiModuleSupport, IWebExceptionHandler)
it is only 15 KB, because it use interfaces from some Microsoft's stuff... while Indy is standalone...

I am not sure you should bother for these 150 KB ... nowadays the software is shipped on DVDs... :)))
0
 

Author Comment

by:yehiaeg
ID: 12133261
you're probably right, i'll just use the indies and after all the size won't differ much with the setup lzma compression,

thanks man
0
 
LVL 12

Expert Comment

by:Ivanov_G
ID: 12133283
always welcome :))
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now