Need Help with httpsocket

Hi,

I want to get response from http status code, using whatsapp API service

Dim url As String = "https://user.maxchat.id/peakwine/api/contacts/check/081572277410"

Dim http As New HTTPSocket
http.SetRequestHeader("accept", "application/json")
http.SetRequestHeader("Authorization", "Bearer UjQrgrwQcFos9mi2dQ4a")

Dim response As String
response = http.Get(url,30)

If http.HTTPStatusCode = 200 Then
' Successful request
MsgBox "Has Whatsapp"
Else
' Error occurred
MsgBox "no Whatsapp"
End If

When I trying to get the response, its shown 301, what is that mean.
the mobile number that I have putted has a whatsapp.

anything wrong with the code?

any helps?

thanks
arief

301 is a redirect. It should also give you the new url. HttpSocket does not automatically follow redirects. URLConnection does. Perhaps use that instead?

1 Like

Ah okay,

so what is the best way to do this, instead of using httpsocket.

thanks
arief

Read through the docs for URLConnection and look at the examples.

https://documentation.xojo.com/api/networking/urlconnection.html#urlconnection

thanks,

Will do some testing with it.

regards,
arief