Is URLConnection broken in 2022r1?

I am trying to send a JSON string to a cloud server. If I paste the URL string into a browser, I get ‘OK’ back which is expected. When it executes in my Xojo app, I get an error 12005 that says “The URL is invalid.” My code is

var url As String = “https:ezmeter.net/kwhuploader.php?MeterData=” + Reading.ToString
URLConnect = new myURLConn
URLConnect.Send(“GET”, url, 60)

and the URL that I pasted in the browse (copied from the debugger) is

https:ezmeter.net/kwhuploader.php?MeterData=[{“SerNo”:“220414010”},{“Data”:[{“MB”:131,“When”:“2022-04-14 14:47:01”,“Port”:“B”,“KWH”:398960,“Hex”:“hex”,“Note”:“”},{“MB”:144,“When”:“2022-04-14 14:47:01”,“Port”:“A”,“KWH”:10241201,“Hex”:“hex”,“Note”:“”}]}]

myURLConn is a subclass of URLConnection that handles the ‘OK’ response. ‘Reading’ is the name of the JSONItem.

That URL is definitely invalid. When you paste it into a URL bar, the browser is making it URL safe under the hood. You need to EncodeURLComponent GET parameters. It is much better to POST JSON data.

5 Likes

You also have the scheme malformed. It should be
https://

You have missing the two slashes

3 Likes

Implemented both fixes and thankfully php did the decoding automatically. POST may be more efficient but the php script didn’t work and I have no idea how to debug it so I stayed with GET.