王朝百科
分享
 
 
 

CreateConnection

王朝百科·作者佚名  2010-04-13  
宽屏版  字体: |||超大  

新建到 HTTP 服务器的连接。如果 UseSSL 值为 True,则 URL 使用 SSL 协议 (https://)。

oConnection = Test.CreateConnection(strServer,lPort, bUseSSL)

参数

strServer

strServer As String:说明要使用的服务器的名称或 IP 地址。请不要包含协议 (http://) 信息。

lPort

lPort As Long:表示 Connection 对象将占用的 HTTP 服务器上的端口。该可选参数的默认值为 80。

bUseSSL

bUseSSL As Boolean:用以确定是否使用 URL 的 SSL 版本 (https://)。

返回值

oConnection As Connection:该对象代表 HTTP 连接。如果无法建立连接,方法将返回 Empty 对象。

备注

为了使用 SSL 协议,HTTP 服务器必须支持正被请求的 URL 的 SSL 并设置为使用该协议。

示例

复制代码

''''''''''''''''''''''''''''''''''''''''''''''''''

' Procedure to send multiple requests for a resource

' using only one connection.

'

Sub SendXRequests(strServer, strPath, lRequests)

Dim lCount, oRequest, oResponse, oConnection

Set oConnection = Test.CreateConnection(strServer )

' check for connection errors

If (oConnection Is Nothing) Then

Test.Trace("Error: Unable to create connection.")

Else

Set oRequest = Test.CreateRequest

oRequest.Path = strPath

oRequest.HTTPVersion = "HTTP/1.1"

For lCount = 1 To lRequests

If (oConnection.IsOpen) Then

Set oResponse = oConnection.Send(oRequest)

' check for a bad connection or request

If (oResponse Is Nothing) Then

Call Test.Trace("Error: invalid request or host not found ")

Else

Call Test.Trace("Server returned: " & oResponse.ResultCode)

End If

End If

Next

oConnection.Close

End If

End Sub

请参阅

Test 对象 | Connection 对象

 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
 
 
静静地坐在废墟上,四周的荒凉一望无际,忽然觉得,凄凉也很美
© 2005- 王朝网络 版权所有