Convert to old xojo

Hi,

I have a code that really works on xojo 2023 r2.2.

dim uc As New URLConnection

dim json As New JSONItem

json.Value("to") = "6281572277410"
json.Value("type") = "text"
json.Value("text") = "Test from xojo"
json.Value("caption") = "Caption test"
json.Value("useTyping") = true
json.Value("skipBusy") = true
json.Value("replyId") = "6281572277410"


uc.RequestHeader("Authorization") = "Bearer UjQrgrwQcFos9mi2dQ4uafa" 

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

dim content As String = uc.SendSync("POST", "https://core.maxchat.id/peak/api/messages", 10)

Label1.Text= str(uc.HTTPStatusCode)

if Label1.text="200" then
Label2.Text="Sukses"
else
Label2.text="GAGAL"
end if

is it possible to convert it into xojo 2018 r4
I have tried it, but there is some difference in this line code

Label1.Text= str(uc.HTTPStatusCode)

I cannot get the response

any helps?

thanks
arief

The target address gave me this response:

<html>��<head><title>301 Moved Permanently</title></head>��<body>��<center><h1>301 Moved Permanently</h1></center>��<hr><center>nginx/1.22.0 (Ubuntu)</center>��</body>��</html>��

But Xojo 2018 uses API1 syntax.

Try this:


dim uc As New httpsocket

dim json As New JSONItem

json.Value("to") = "6281572277410"
json.Value("type") = "text"
json.Value("text") = "Test from xojo"
json.Value("caption") = "Caption test"
json.Value("useTyping") = true
json.Value("skipBusy") = true
json.Value("replyId") = "6281572277410"
uc.requestHeaders.AppendHeader("Authorization","Bearer UjQrgrwQcFos9mi2dQ4uafa" )
uc.SetRequestContent(json.ToString, "application/json")

dim content As String 
content = uc.SendRequest("POST", "https://core.maxchat.id/peak/api/messages", 10)

dim h as string
h = str(uc.HTTPStatusCode)
if h ="200" then
  msgbox "Sukses"
else
  msgbox "GAGAL"
end if

I have fix the url and code, but still go an error 301
when I do running on newer xojo, it works

dim uc As New httpsocket

dim json As New JSONItem

json.Value("to") = "6281572277410"
json.Value("type") = "text"
json.Value("text") = "Test from xojo"
json.Value("caption") = "Caption test"
json.Value("useTyping") = true
json.Value("skipBusy") = true
json.Value("replyId") = "6281572277410"
uc.requestHeaders.AppendHeader("Authorization","Bearer UjQrgrwQcFos9mi2dQ4uaa" )
uc.SetRequestContent(json.ToString, "application/json")

dim content As String 
content = uc.SendRequest("POST", "https://core.maxchat.id/peakwine/api/messages", 10)

dim h as string
h = str(uc.HTTPStatusCode)
MsgBox str(h)
if h ="200" then
msgbox "Sukses"
else
msgbox "GAGAL"
end if

Error 301 isnt an error. It is a redirect… it means the page you are looking for is now somewhere else.
Maybe it relates to the HTTPS aspect of the URL
Try

dim uc As New HTTPSecureSocket

… thats the limit of my knowledge… :slight_smile: Im not an expert here.

1 Like

When you get a 301 response, look at the headers. There will be one named “Location” which has the new URL.

2 Likes