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 對象

相關詞條

熱門詞條

聯絡我們