Posting JSON using url connection

Hi,
I found a sample about url connection on language reference.

Var json As New JSONItem
json.Value("ID") = 123456

mySocket.SetRequestContent(json.ToString, "application/json")
mySocket.Send("POST", "http://127.0.0.1:8080/GetCustomer")

I have a question, The url that I want to use for post the json data is using token key and user id.
where i have to put it here. is there any other method to define it. I have tried to add it on the url, but seems not working.

any helps

thanks
arief

You must read your API docs, but usually some infos follows in the header as:

Var uc As New URLConnection

Var json As New JSONItem

json.Value("ID") = 123456

uc.RequestHeader("token") = "ajshdfjahsdhfkahsdjkfha" // follow your API docs
uc.RequestHeader("another_header_data") = "ajshdfjahsdhfkahsdjkfha" // more examples

uc.SetRequestContent(json.ToString, "application/json")

Var content As String = uc.SendSync("POST", "http://127.0.0.1:8080/GetCustomer", 10)

Thanks its works.

but one more questions, how to grab the status. to make sure the data is posted or not.
in Linux shell via curl its shown, its mention if status=200 means success.
but I don’t know how to show the success message here.

thanks
regards,
arief

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

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

thanks so much.

regards
arief

1 Like