高分请教有关WebBrowser的使用方法

FinalLover 2002-09-27 11:39:15
本人使用WebBrowser的Navigator或者Navigator2方法打开一个asp文档并且传递参数进去,但是asp文档无法获得参数,请教是什么原因?

vb源码:
Private Sub cmdSubmit_Click()
Dim strURL As String, strFormData As String
Dim strData As String
strURL = Trim$(txtURL.Text)
strFormData = "name=" & Trim$(txtName.Text) & "&password=" & Trim$(txtPassword.Text)
Call WBTest.Navigate2(strURL, 64, "_blank", strFormData, "hello")
End Sub

asp源码:

<%@ Language=VBScript %>
<%
dim strName
dim strPassword
strName=Trim(Request.Form("name"))
strPassword=Trim(Request.Form("password"))
Response.Write(strName)
Response.Write(strPassword)
if strName="KingZhang" and strPassword="123456" then
Response.Write("<font color=green>登陆成功</font>")
else
Response.Write("<font color=red>非法登陆用户!</red>")
end if

%>
<HTML>
<HEAD>
<META NAME="GENERATOR" charset="gb2312" Content="Microsoft Visual Studio 6.0">
</HEAD>
<BODY>

<P> </P>

</BODY>
</HTML>
...全文
181 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
FinalLover 2002-09-27
  • 打赏
  • 举报
回复
非常感谢antshome(星星我来了) ,问题解决了。但是我的疑问还是没办法消除,不过之前我不知道WebBrowser还可以直接访问Web页面中间元素。现在能做到这样的话,用一个初始Web页把要提交的参数设置好了之后,再调用b表单的Submit方法是一个不错的方法,再次感谢!
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 Navigate2 method issues an HTTP GET transaction. This parameter is ignored if URL is not an HTTP URL.
antshome 2002-09-27
  • 打赏
  • 举报
回复
Navigate2 Method

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

Description

Navigates to the resource identified by a Universal Resource Locator (URL) or to the file identified by a full path. The Navigate2 method extends the Navigate method to support browsing on special folders—such as Desktop and My Computer—that are represented by a pointer to an item identifier list (PIDL). However, this is not applicable to the Visual Basic programming language. For information on this functionality, see the Using the WebBrowser Control from C/C++ section.


Syntax
object.Navigate2 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 of the resource to display or the full path to the file location.
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 Navigate2 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.


Applies To

InternetExplorer, WebBrowser
FinalLover 2002-09-27
  • 打赏
  • 举报
回复
请问:在WebBrwoser控件里提供的Navigate或者Navigate2方法中提供了传递数据的参数,调用方式为:WebBrowser1.Navigate2(URL,[Flags],[TargetFrameName],[PostData],[Headers])
其中PostData参数就是一个提交参数字符串,例如"name=aaa&password=123",但问题是为什么这个方法并不是有效的,服务器端不能取得数据?
如果这个方法是有效的话就不需要用一段html代码模拟这种调用了。
antshome 2002-09-27
  • 打赏
  • 举报
回复
post方式提交数据


Option Explicit

Private Sub Command1_Click()
Dim szValue As String
WebBrowser1.Document.body.innerHTML = "<form id=post method=post action=http://地址/xxx.php><input type=text value='" & szValue & "'></form>"
WebBrowser1.Document.Forms("post").submit
End Sub

Private Sub Form_Load()
WebBrowser1.Navigate2 "about:blank"
End Sub
trytryba 2002-09-27
  • 打赏
  • 举报
回复
没试过,学习。
antshome 2002-09-27
  • 打赏
  • 举报
回复
strURL = Trim$(txtURL.Text) & "?name=" & Trim$(txtName.Text) & "&password=" & Trim$(txtPassword.Text)

Call WBTest.Navigate2(strURL)
FinalLover 2002-09-27
  • 打赏
  • 举报
回复
但是用这种方式传递的数据能够看到,如果把地址栏里的地址复制再回车不就又可以顺利的进入到该页面里去了。所以程序要求不能用Get方式传递,只能用post方式而且加密传递。再请教。
fangboy 2002-09-27
  • 打赏
  • 举报
回复
直接跟在URL后面发过去不行吗?

7,763

社区成员

发帖
与我相关
我的任务
社区描述
VB 基础类
社区管理员
  • VB基础类社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧