Skip to content

Migrating from BareboneThunks to cTlsSocket #3 #65

@gaouservbf

Description

@gaouservbf

This will be more generic than the other questions, I apologize if I went too blurred here like if it was me from like 2022.

How do we implement chunked transfer in sync data receiving?

Private Sub FetchChannelMessages(ByVal sChannelId As String, Optional ByVal lLimit As Long = 10)

    Dim tlsSocket As New cTlsSocket
    Dim sPayload As String
    Dim sRequest As String
    Dim sResponse As String
    
    
    ' Create the API request path
    Dim sPath As String
    sPath = "api/v10/channels/" & sChannelId & "/messages?limit=" & lLimit
    
    sRequest = "GET /" & sPath & " HTTP/1.1" & vbCrLf & _
              "Host: " & m_sBaseUrl & vbCrLf & _
              "Authorization: " & m_sToken & vbCrLf & _
              "Connection: close" & vbCrLf & vbCrLf
    
    ' Configure and connect socket
    ' Allow TLS 1.2 or 1.3
    tlsSocket.SyncConnect "discord.com", 443, , , ucsTlsSupportAll Or ucsTlsIgnoreServerCertificateErrors
    
    ' Send request
    tlsSocket.SyncSendText sRequest
    
    ' Receive response (blocking)
    sResponse = tlsSocket.SyncReceiveText
    
Open App.Path + "\fcm.txt" For Output As #1
'ParseHttpResponse(sResponse, False)
Print #1, sResponse
Close #1
    ' Clean up
    tlsSocket.Close_
    Set tlsSocket = Nothing

End Sub

Unlike the other functions, this is supposed to receive a quite long data.

Image

It got trimmed in 6821 characters, It's quite a weird number but HTTP headers likely don't count in the chunked transfers.
I'm pretty sure the server uses chunked transfering.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions