龙卷风
关键字:asp,activex控件,数字签名,安全
问题提出:
activex控件得到客户端的信息,如何传递到服务端???
一种方法就是得到值后,使用get,post方式提交,这可能也是最常用的.
有没有更好一些的方法呢?
能不能在控件中直接向服务器发出请求而得到数据呢?
打开vb6,新建activex控件工程。
工程名:focx,用户控件名:uc3
添加1个按钮,2个文本框
代码如下:
option explicit
private sub command1_click()
注意字符串和数字的写法有些区别
使用asyncread通过http发送你的请求
usercontrol.asyncread "http://yang/xml/activex.asp?s1=" & text1.text & "", vbasynctypebytearray
usercontrol.asyncread "http://yang/xml/activex.asp?s1=" & text1.text, vbasynctypebytearray
end sub
asyncreadcomplete 事件用来从asp页面接受和分析。
当容器刚完成一个异步读取请求时 , 发生该事件?
asyncprop 中的数值指定了已完成的某个异步数据读取请求,
它与前一个 asyncread 方法调用中的数据匹配。
asyncreadcomplete 事件过程中应包含错误处理代码,因为错误状态会终止下载。
如果发生了这种情况,当访问 asyncproperty 对象的 value 属性时将会发生错误。
private sub usercontrol_asyncreadcomplete(asyncprop as asyncproperty)
on error goto errhandle
text2.text = bytearraytostring(asyncprop.value)
errhandle:
err.raise 601, "异步读取发生了错误", err.description
end sub
将字节数组转换成字符串
public function bytearraytostring(bytarray() as byte) as string
dim sans as string
sans = strconv(bytarray, vbunicode)
bytearraytostring = sans
end function
我们来看看http://yang/xml/activex.asp这个文件
<%
dim str
str=request("s1")
if str="name" then
response.write ("龙卷风")
elseif str="age" then
response.write ("26")
else
response.write ("没有可用信息返回")
end if
%>
很简单,使用request接受参数,response返回。
这个例子可以进一步处理,将服务器名以属性的方式传递给控件。
比如:<param name="servername" value="192.168.0.1 ">
然后在程序中得到,就可以使用了,如:
usercontrol.asyncread "http://192.168.0.1/xml/activex.asp?s1=" & text1.text & "", vbasynctypebytearray
然后在程序中得到就可以灵活处理了。
