Friday, June 15, 2012

TWebBrowser and POST Request

var
  strData: string;
  PostData: OleVariant;
  Headers: OleVariant;
  i: Integer;
begin
  {1. you must create a string with parameter names and values
  Result string must be in the next format:
  Param1 = Value1&Param2 = Value2&Param3 = Value3...}
  strData := 'Param1Name=' + HTTPEncode(Param1Value) + '&' +
    'Param2Name=' + HttpEncode(Param2Value) + ...;

  {2. you must convert a string into variant array of bytes and
   every character from string is a value in array}
  PostData := VarArrayCreate([0, Length(strData) - 1], varByte);

  { copy the ordinal value of the character into the PostData array}
  for i := 1 to Length(strData) do
    PostData[i-1] := Ord(strData[i]);

  {3. prepare headers which will be sent to remote web-server}
  Headers := 'Content-Type: application/x-www-form-urlencoded' + #10#13;

  {4. you must navigate to the URL with your script and send as parameters
  your array with POST-data and headers}

  yourWebBrowserComponent.Navigate('http://www.yourdomain.com/your_post_script.asp', EmptyParam, EmptyParam, PostData, Headers);
end;

0 comments:

Post a Comment

 
Related Posts Plugin for WordPress, Blogger...