About HttpClient (gb.net.curl) Head method

For questions about Gambas web tools.
Post Reply
kuramayouko
Posts: 3
Joined: Monday 19th December 2022 11:55am

About HttpClient (gb.net.curl) Head method

Post 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.
User avatar
BruceSteers
Posts: 1059
Joined: Thursday 23rd July 2020 5:20pm
Location: Isle of Wight
Contact:

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

Post 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.
If at first you don't succeed , try something different.
BruceS
kuramayouko
Posts: 3
Joined: Monday 19th December 2022 11:55am

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

Post 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
Attachments
Screenshot_20221219_100448.png
Screenshot_20221219_100448.png (6.36 KiB) Viewed 216 times
kuramayouko
Posts: 3
Joined: Monday 19th December 2022 11:55am

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

Post by kuramayouko »

Nevermind i was using the wrong method it should be

Code: Select all

client.Get(headers)
Post Reply