如何使浏览器(ActiveX控件)post数据?(100分)

  • 主题发起人 主题发起人 alum
  • 开始时间 开始时间
A

alum

Unregistered / Unconfirmed
GUEST, unregistred user!
程序有一个Twebbrowse,那么,想通过程序直接向指定页面post数据。然后
由twebbrowse接收返回信息,如何才能做到?
 
1.用NMHTTP:nmhttp1.post(url,postdata);2.用文件对象将POST后的内容保存到本地文件;3。用WEBBROWSER.Navigate(WideString(Filename));
 
我的方法:
拷贝一个你指定的页面到本地,对其中需要自己填写的数据用[]进行
标识,比如说[TEXT],[USERNAME],[PASSWORD]等等。用WebBrowser
先加载这个本地页面,然后修改WebBrowser的Document.innerHtml,
把前面定义的[TEXT],[USERNAME],[PASSWORD]等标示用正确的数据
替换,找到Submit Button,Click(这些都可以通过程序完成),
返回的数据自然在WebBrowser中。

据说nmhttp对asp不起作用。
 
没有那么复杂,直接用webbrowser.navigate就行
你以为它白带了四个参数,太困了,明天再说吧
 
这是Visual Studio 中MSDN的介绍,因为Webbrowser是IE带的,所以在Delphi
中应当一样使用。

Navigate Method

--------------------------------------------------------------------------------

Description

Navigates to the resource identified by a Universal Resource Locator (URL) or to the file identified by a full path.


Syntax
object.Navigate URL [Flags,] [TargetFrameName,] [PostData,] [Headers]



Part Description
object Required. An object expression that evaluates to an object in the Applies To list.
URL Required. A string expression that evaluates to the URL, full path, or Universal Naming Convention (UNC) location and name of the resource to display.
Flags Optional. A constant or value that specifies whether to add the resource to the history list, whether to read from or write to the cache, and whether to display the resource in a new window. It can be a combination of the following constants or values. Constant Value Meaning
navOpenInNewWindow 1 Open the resource or file in a new window.
navNoHistory 2 Do not add the resource or file to the history list. The new page replaces the current page in the list.
navNoReadFromCache 4 Do not read from the disk cache for this navigation.
navNoWriteToCache 8 Do not write the results of this navigation to the disk cache.

TargetFrameName Optional. String expression that evaluates to the name of an HTML frame in URL to display in the browser window. The possible values for this parameter are: _blank Load the link into a new unnamed window.
_parent Load the link into the immediate parent of the document the link is in.
_self Load the link into the same window the link was clicked in.
_top Load the link into the full body of the current window.
<window_name> A named HTML frame. If no frame or window exists that matches the specified target name, a new window is opened for the specified link.

PostData Optional. Data to send to the server during the HTTP POST transaction. For example, the POST transaction is used to send data gathered by an HTML form to a program or script. If this parameter does not specify any post data, the Navigate method issues an HTTP GET transaction. This parameter is ignored if URL is not an HTTP URL.
Headers Optional. A value that specifies additional HTTP headers to send to the server. These headers are added to the default Internet Explorer headers. The headers can specify things like the action required of the server, the type of data being passed to the server, or a status code. This parameter is ignored if URL is not an HTTP URL.

的确,他带的参数不白给。
 
曾经看过某文描述postdata参数时,称其为布尔值。因此有些模糊。

请gongming与hugdog说明一下postdata 的详细用法。

(没办法,新手一个)
 
hugdog是谁啊?

PostData用于向页面提交信息,如stPostData:='animal=cat&color=brown' ;
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
{头信息当PostData使.}
vHeaders:= 'Content-Type: application/x-www-form-urlencoded'+ #10#13#0;
vPostData:= VarArrayCreate([0, Length(stPostData)], varByte);
for iLoop := 0 to Length(stPostData)- 1 do
begin
vPostData[iLoop]:= Ord(stPostData[iLoop+ 1]);
end;
{结束字符}
vPostData[Length(stPostData)]:= 0;
{Set the type of Variant, cast}
TVarData(vPostData).vType:= varArray;
end;
vWebAddr:= stURL;
wbWebBrowser.Navigate2(vWebAddr, vFlags, vFrame, vPostData, vHeaders);
end;
 
多谢hubdog!(抱歉,我这人眼睛不好使。。。怎么g/b都混。。)
 
呵呵,你用nmhttp,简单的调一个函数就可以了(建议)
 
接受答案了.
 

Similar threads

S
回复
0
查看
3K
SUNSTONE的Delphi笔记
S
S
回复
0
查看
2K
SUNSTONE的Delphi笔记
S
S
回复
0
查看
1K
SUNSTONE的Delphi笔记
S
S
回复
0
查看
900
SUNSTONE的Delphi笔记
S
后退
顶部