Einzelnen Beitrag anzeigen

Kamil

Registriert seit: 17. Aug 2002
178 Beiträge
 
#2

Re: IdHTTPServer-control hätte gerne zusätzliches Info

  Alt 28. Sep 2003, 19:45
Zitat:
Q: How can I pass PostData when I Navigate to a URL?

A: I call the below method with a URL destination, PostData in the format of 'animal=cat&color=brown' etc. and the TWebBrowser object that I want to load the URL inside of...

Code:
procedure TDBModule.Navigate(stURL, stPostData: String; var wbWebBrowser: TWebBrowser);
var
  vWebAddr, vPostData, vFlags, vFrame, vHeaders: OleVariant;
  iLoop: Integer;
begin
  {Are we posting data to this Url?}
  if Length(stPostData)> 0 then
  begin
    {Require this header information if there is stPostData.}
    vHeaders:= 'Content-Type: application/x-www-form-urlencoded'+ #10#13#0;
    {Set the variant type for the vPostData.}
    vPostData:= VarArrayCreate([0, Length(stPostData)], varByte);
    for iLoop := 0 to Length(stPostData)- 1 do   // Iterate
    begin
      vPostData[iLoop]:= Ord(stPostData[iLoop+ 1]);
    end;   // for
    {Final terminating Character.}
    vPostData[Length(stPostData)]:= 0;
    {Set the type of Variant, cast}
    TVarData(vPostData).vType:= varArray;
  end;
  {And the other stuff.}
  vWebAddr:= stURL;
  {Make the call Rex.}
  wbWebBrowser.Navigate2(vWebAddr, vFlags, vFrame, vPostData, vHeaders);
end; {End of Navigate procedure.}
This tip provided by Craig Foley based on techniques from Nathan Wilhelmi's Usenet posting to borland.public.delphi.internet on the 31/1/99

A: Here's another option:

Code:
procedure TForm1.SubmitPostForm;
var
  strPostData: string;
  Data: Pointer;
  URL, Flags, TargetFrameName, PostData, Headers: OleVariant;
begin
  {
 
  <form method="post" action="http://127.0.0.1/cgi-bin/register.pl">
  <input type="text" name="FIRSTNAME" value="Hans">
  <input type="text" name="LASTNAME" value="Gulo">
  <input type="text" name="NOTE" value="thats it">
  <input type="submit">
  </form>
  }
  strPostData := 'FIRSTNAME=Hans&LASTNAME=Gulo&NOTE=thats+it';
  PostData := VarArrayCreate([0, Length(strPostData) - 1], varByte);
  Data := VarArrayLock(PostData);
  try
    Move(strPostData[1], Data^, Length(strPostData));
  finally
    VarArrayUnlock(PostData);
  end;
  URL := 'http://127.0.0.1/cgi-bin/register.pl';
  Flags := EmptyParam;
  TargetFrameName := EmptyParam;
  Headers := EmptyParam; // TWebBrowser will see that we are providing
                         // post data and then should automatically fill
                         // this Headers with appropriate value
  WebBrowser1.Navigate2(URL, Flags, TargetFrameName, PostData, Headers);
end;
This tip provided by Hans Gulo.
  Mit Zitat antworten Zitat