[Gambas-user] httpget issue

T Lee Davidson t.lee.davidson at gmail.com
Thu Mar 2 17:16:43 CET 2023


On 3/2/23 09:42, Antonio Teixeira wrote:
> Hi everyone,
> 
> I am trying to use the httpget class in gambas but I am having issues.
> The curl that is working is :
> 
[snip]
> 
> The code I am using in gambas is :
> 
> Private Sub DoLogin()
>    Dim data As String
>    Dim headers As New String[]
>    Dim resposta As String
> 
>    hClient.URL = "https://192.168.10.110:50301/api/user/Login <https://192.168.10.110:50301/api/user/Login>"
>    hClient.Async = False
>    hclient.Auth = Net.AuthNone
>    hclient.SSL.VerifyHost = False
>    hclient.SSL.VerifyPeer = False
>    hClient.Timeout = 2
>    headers.Add("Content-Type: application/json")
>    data = "username=a&password=a"
>    hClient.Post("application/json", data) ', headers)
>    'hClient.get(headers)
>    Resposta = hclient.Peek()
>    Message(Resposta, "OK")
> End Sub
> 
> 
> I am getting always "Bad Request"
> 
> Any help please?
> 
> Thanks in advance.
> 
> Atentamente / Regards
> 
> António Teixeira

First off so that others don't get confused, there is no httpget class. I think you probably meant HttpClient.

It appears the data you are sending is not in JSON format:
data = "username=a&password=a"

try:
data = "{'username'='a'&'password'='a'}"

Tip: The gb.util.web component has a JSON class that has encode and decode methods:
https://gambaswiki.org/wiki/comp/gb.util.web/json
(You may already know this, but others may not.)


-- 
Lee



More information about the User mailing list