请输入您要查询的百科知识:

 

词条 CreateConnection
释义

新建到 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 对象

随便看

 

百科全书收录4421916条中文百科知识,基本涵盖了大多数领域的百科知识,是一部内容开放、自由的电子版百科全书。

 

Copyright © 2004-2023 Cnenc.net All Rights Reserved
更新时间:2025/3/4 0:51:11