Page 1 of 1

About HttpClient (gb.net.curl) Head method

Posted: Monday 19th December 2022 12:09pm
by kuramayouko
I'm trying to use this Library on my code but still unable to set up the headers maybe i missed something.

Code: Select all

Dim client As New HttpClient
    Dim url As String = "https://mysite/validate.json"
    Dim headers As String[]
    
    headers.Add("accept: application/json")
    headers.Add("key: " & Me.Key)
 
    client.Async = False
    client.Timeout = 20
    client.Encoding = "utf-8"
    client.URL = url
    client.UserAgent = Me.CustomUA
    client.Debug = True
    
    client.Head(headers) '-> Error in this line. Cannot load class 'String[]] : Out of bounds
    
    client.Get
Even if I use:

Code: Select all

client.Head(["accept: application/json","key: " & Me.key])
Still get the same error.

Re: About HttpClient (gb.net.curl) Head method

Posted: Monday 19th December 2022 12:34pm
by BruceSteers
you must initialize the string array first

either use...

Dim headers As New String[]
or
Dim headers As String[] = []

You must do that before you can directly use headers.Add() method.

Re: About HttpClient (gb.net.curl) Head method

Posted: Monday 19th December 2022 1:19pm
by kuramayouko
Tried that but still get the same error i even changed the code to print all the Strings in the array

Code: Select all


Dim client As New HttpClient
    Dim url As String = "https://mysite/validate.json"
    
    Dim string As String
    Dim headers As New String[]
    
    headers.Add("accept: application/json")
    headers.Add("key: " & Me.Key)
 
   'Made a loop to show all the values from the Array, works fine 
    For Each string In headers 
      Print string
    Next
 
    client.Async = False
    client.Timeout = 20
    client.Encoding = "utf-8"
    client.URL = url
    client.UserAgent = Me.CustomUA
    client.Debug = True
    
    client.Head(headers) '-> Same error. Cannot load class 'String[]] : Out of bounds
    
    client.Get

And im the local variable show this

Re: About HttpClient (gb.net.curl) Head method

Posted: Monday 19th December 2022 2:02pm
by kuramayouko
Nevermind i was using the wrong method it should be

Code: Select all

client.Get(headers)