TWebBrowser and POST request

Today I want to describe how you can send some data to web-server from your remote script using TWebBrowser component.

 
 
 
  
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 ;

Of course, the same task can be solved with any internet component which implement the http-client (not only TWebBrowser). But for every component the data for script will be posted by own rules (most components have pre-defined properties for this task).

转载于:https://www.cnblogs.com/dwbboy/archive/2011/02/22/1960288.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值