B4J Question HttpJob in server.handler

MichalK73

Well-Known Member
Licensed User
Longtime User
Hello.
I have a problem.
I have the handler
B4X:
srvr.AddHandler ("/get/*", "link", False)
The server reads in the format '' https: // localhost / get / username / password '
Based on the data from the link, a link is downloaded that downloads from another server via httpjob. When he wants to send via resp, no result.

How to solve it?

B4X:
Sub Handle(req As ServletRequest, resp As ServletResponse)
    Dim url As String = req.FullRequestURI
    url = url.SubString(url.IndexOf("get/")+4)
    Dim user As String = url.SubString2(0,url.IndexOf("/"))
    Dim pass As String = url.SubString(url.IndexOf("/")+1)
    
    Dim link As String = DBM.SQLSelectSingleResult("select link from table where user=? and pass=?", Array As String(user, pass))
    If link.Length >10 Then
        resp.Write("test1") '=> send OK
        Dim j As HttpJob
        j.Initialize("", Me)
        j.Download(link)
        Wait For (j) JobDone(j As HttpJob)
        If j.Success Then
            resp.Write("test2") '=> no send , webbrowser empty
            Dim value As String = j.GetString
            Log(value) => 'value is OK
            resp.Write(value) ' => no send , webbrowser empty
            j.Release
        End If
    Else
        resp.Write("Bad :(")
    End If
End Sub
 

MathiasM

Active Member
Licensed User
I am unable to test right now. And it's a bit a shot in the dark.
But have you tried handling on the main thread? I don't exactly know how the Wait For works internally, but it could be a threading issue.
So instead of

B4X:
srvr.AddHandler ("/get/*", "link", False)

try

B4X:
srvr.AddHandler ("/get/*", "link", True)

Also, have you debugged your "link" variable? Are you 100% sure your link is actually returning data?

As a sidenote: You're passing credentials via GET requests and save passwords unhashed, both are considered very bad practice and are insecure.
 
Upvote 0
Top