Skip to content

cHttpClient Component Overview

Introduction

cHttpClient is an HTTP client component based on WinHTTP that provides complete HTTP request functionality, supporting sync/async requests, chainable calls, JSON processing, Cookie management, and more. Also provides cSSEClient for SSE (Server-Sent Events) real-time message reception.

Features

FeatureDescription
HTTP MethodsSupports GET/POST/PUT/DELETE/OPTIONS
Data FormatsJSON, Form-UrlEncoded, Text auto-processing
Sync/AsyncSupports sync and async request modes
Chainable APIFluent API design with chainable operations
Cookie ManagementAuto parse and set Cookies
SSL SupportAuto ignore SSL certificate errors
EncodingSupports UTF-8 encoding auto-conversion
Debug ModeProvides detailed request/response debug info
SSE SupportIndependent SSE client for real-time messages

Quick Start

HTTP GET Request

vb
Dim http As New cHttpClient
Dim result As String

' Simple GET request
result = http.SendGet("https://api.example.com/users").ReturnText()

' GET request with query parameters
result = http.SendGet("https://api.example.com/users") _
    .AddQueryParam("page", "1") _
    .AddQueryParam("limit", "10") _
    .ReturnText()

HTTP POST Request (JSON)

vb
Dim http As New cHttpClient
Dim json As cJson
Set json = New cJson
json.AddItem "name", "John"
json.AddItem "age", 25

Set http.RequestDataJson = json

Dim response As cJson
Set response = http.SendPost("https://api.example.com/users").ReturnJson()

HTTP POST Request (Form)

vb
Dim http As New cHttpClient

http.RequestDataForm("username") = "admin"
http.RequestDataForm("password") = "123456"

Dim result As String
result = http.SendPost("https://api.example.com/login").ReturnText()

Async Request

vb
Private WithEvents HttpClient As cHttpClient

Private Sub StartAsyncRequest()
    Set HttpClient = New cHttpClient
    HttpClient.Async(True).SendGet("https://api.example.com/data")
End Sub

Private Sub HttpClient_OnResponseFinished()
    Debug.Print "Response complete: " & HttpClient.ReturnText()
End Sub

Private Sub HttpClient_OnError(ByVal ErrorNumber As Long, ByVal ErrorDescription As String)
    Debug.Print "Error: " & ErrorDescription
End Sub

SSE (Server-Sent Events)

vb
Private WithEvents SSE As cSSEClient

Private Sub InitializeSSE()
    Set SSE = New cSSEClient
    SSE.AutoReconnect = True
    SSE.ReconnectInterval = 3000  ' 3 second reconnect interval
    SSE.MaxReconnectAttempts = 10
    Call SSE.Connect("https://api.example.com/events")
End Sub

Private Sub SSE_OnOpen()
    Debug.Print "SSE connection established"
End Sub

Private Sub SSE_OnMessage(EventName As String, Data As String, Id As String)
    Debug.Print "Received message: " & EventName & " = " & Data
End Sub

Private Sub SSE_OnError(Description As String, ErrorNumber As Long)
    Debug.Print "SSE error: " & Description
End Sub

Private Sub SSE_OnClose()
    Debug.Print "SSE connection closed"
End Sub

References

  • Microsoft WinHTTP Services, version 5.1
  • Microsoft Scripting Runtime
  • cJson.cls
  • cTimer.cls (required for SSE)

File Structure

FileDescription
cHttpClient.clsHTTP client main class
cSSEClient.clsSSE client implementation
mSSEDemo.basSSE usage example
SSE_Client_使用文档.mdSSE detailed documentation

Last Updated: 2026-05-17

VB6 and LOGO copyright of Microsoft Corporation