Post JSON/REST

Hi, I’ve always used JSON/REST to import data using this code.
dim restUrl as String = “http://xxxxx/xxxx”
dim response As String
dim username as String = userrest
dim password as String = password
dim socket as new HTTPSocket
dim timeout as Integer = 30
socket.SetRequestHeader(“Authorization”, “Basic " + EncodeBase64(username+”:"+password))
response = socket.get(RestUrl, timeout)
response = DefineEncoding(response, Encodings.UTF8)
Now I need to send some data, how can I do it?
I can create the string.
I’d like a small example.

Similar to HTTPSocket, use URLConnection.SetRequestContent and URLConnection.Send.

Tom, Thank you but I’m not that prepared I’d appreciate a small example, if possible. The string I should send is similar to the following
[{“firstName”:“ROSSI”,“lastName”:“LUCIA”,“birthDate”:“06/06/1989”,“Sex”:“F”}]
I read that you had to use POST.

It’s right in the documentation. URLConnection — Xojo documentation

1 Like

Hi Thom, I looked at the documentation,
but instead of clarifying my ideas, it confused them.
I wrote this code, but I still have a lot of doubts.

Dim formtext As String ={“firstName”:“ROSSI”,“lastName”:“LUCIA”,“birthDate”:“06/06/1989”,“Sex”:“F”}]
Dim response As String
Dim username As String = “xxxx”
Dim password As String = “syyyy”
dim mySocket as new URLConnection

which of the two codes?
mySocket.SetRequestContent(formtext, “application/application/x-www-form-urlencoded”) this
mySocket.SetRequestContent(formtext.ToString, “application/json”) or this

mySocket.Send(“POST”, “https://xxxx/yyyy/xxx”)

response= ??? how to get it

username password how to insert them

where am I wrong? can you help me?