Android Question problem in if statement

Sofiya

Member
Licensed User
B4X:
Sub JobDone (Job As HttpJob)
Dim result As String
    Log("JobName = " & Job.JobName & ", Success = " & Job.Success)
    ProgressDialogHide
'    Job.GetRequest.Timeout = 60000
    If Job.Success = True Then
        Select Job.JobName
            Case "Login"
                ToastMessageShow(Job.GetString,True)
           
                result = Job.GetString
            If result  = "success" Then  'here i face the problem
                StartActivity(Outlet)
                Activity.Finish
            End If
        End Select
    Else
        Log("Error: " & Job.ErrorMessage)
        ToastMessageShow("Error:" & Job.ErrorMessage,True)
    End If
    Job.Release
End Sub

In the above code i face the problem that in the line 'if result = "success" then', even though result variable got "success" value it is not entering inside if statement. Please anyone help me to solve this problem.
 

BillMeyer

Well-Known Member
Licensed User
Longtime User
Put a Log(job.GetString) between

result = Job.GetString
' Put it here
If result = "success" Then

and I think you will see that you are not getting the string "success".

Post the log here and we can then help you further.
 
Upvote 0

Sofiya

Member
Licensed User
B4X:
*** Service (starter) Create ***
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
*** Service (httputils2service) Create ***
** Service (httputils2service) Start **
JobName = Login, Success = true
"failed"

when i enter wrong username and password then above log is show.
 
Upvote 0

sorex

Expert
Licensed User
Longtime User
and if the username and password is correct? does it give "success" or nothing at all?

that failed has double quotes around it. is it like that or added manually in this post?
 
Upvote 0

lip

Active Member
Licensed User
Longtime User
1. Trim your result variable. You might be getting lead or trailing " " characters
2. Put and Else after your if and log("Else: " & result) to see if you get "Else success" or something else?
 
Upvote 0

sorex

Expert
Licensed User
Longtime User
also for success? then your if check ain't correct.

try

B4X:
 If result.contains("success") Then
 
Upvote 0

Sofiya

Member
Licensed User
1. Trim your result variable. You might be getting lead or trailing " " characters
2. Put and Else after your if and log("Else: " & result) to see if you get "Else success" or something else?

1. Trim is added.
2. For correct username and password it enters inside the else condition throw the log as "success".
 
Upvote 0

sorex

Expert
Licensed User
Longtime User
hard to tell without seeing the output of job.getstring or the source on the server.

maybe also "success" or whitespace or a linefeed
 
Upvote 0

Marco Maria Vilucchi

Active Member
Licensed User
Longtime User
I think that
If Job.Success = True
is the correct if.
You made it before your problem and you already know it's true. (program is at this statement only if Job.Success = True)
Why do you want ask again?
 
Upvote 0

sorex

Expert
Licensed User
Longtime User
it's not if the request is successful that it will return the "success" string aswell so she needs both checks.
 
Upvote 0

OliverA

Expert
Licensed User
Longtime User
If Job.Success = True
is the correct if.
You made it before your problem and you already know it's true. (program is at this statement only if Job.Success = True)
Why do you want ask again?
Job.Success only indicates that the HTTP status code was 2xx. Any other return code (3xx,4xx,5xx, etc) will result in a false. Just because the HTTP status code is 2xx does not mean that the returned information is of a "true" nature. It really just means that the HTTP call worked.

thank you so much but what is the problem in my previous coding.
Since "failed" is in quotes, "success" may also be and then you would need
B4X:
If result  = $""success""$ Then
. The contains though takes care of anything else (spaces, special characters, etc.).
 
Upvote 0
Top