I want to send a post request with the body to an address, but there is an infinite waiting. Where did I go wrong?
My authorization function:
At the moment I do not pass login and password. I just specify them directly.
I guess 'm.port' is defined elsewhere? If that's missing it might be the problem...
Try 'urlXfer.setMessagePort' instead of setPort.
I usually see wait() being used within a 'while true' loop but you're blowing straight through if nothing happened in 100ms so it could be related to that.
Your body JSON looks like it's malformed - hard to tell with all those Chr(34)s though! Try formatjson instead:
requestBody = formatjson({"name":"Roku"})
In terms of the infinite waiting more generally, one thing I do is make an roTimespan before the wait loop, then I can check it and abort the request after it's gone on too long.
Thank you for replying! I listened to your advices. But still doesn't work.
Result:
About m.port, I defined it in init(). I also noticed that after I delete the archive from the device, my boot window appears for a second, which is declared at the beggining of the function loginClient(...)
msg has to be something or invalid! You're not checking for anything other than a roUrlEvent. Try adding print msg or print type(msg) after the wait or another else. When it comes to debugging BS, print is your best friend. I don't see how it could hang unless in your original code you're calling loginClient in a loop. I would also check for invalid before anything else just to make sure you never try to use msg for something if it's invalid.
msg = wait(100, m.port)
print type(msg)
if msg = invalid
print "Canceling..."
urlXfer.asyncCancel()
else if type(msg) = "roUrlEvent"
print "Success!"
m.deviceId = msg.getString()
else
stop
end if
If it never hits the print, something is seriously wrong. I would try creating a message port to assign to urlXfer and not using m.port to see what happens.
100ms isn't much time to wait, so I wouldn't be too surprised if you hit that code every time.
P.S. - code is easier to read if you use code tags rather than spoiler tags. Look for the ... when you're making a post and it will expand to show more options. The code tag button looks like </>.
sub loginClient(login as String, password as String)
This doesn't look like it is done inside a task thread. It isn't using m.top.login or m.top.password to pass fields into the task. This looks like it is done in the render thread? For the url object to be created it must be done within a task.
urlXfer = CreateObject("roUrlTransfer")