B4J Question [WebApp] and B4A in ssl and filter

Fabrice La

Active Member
Licensed User
Longtime User
My first problem was:
How to use file upload from B4A in ssl (https://) on the [WebApp Server] ? to avoid :
Error: javax.net.ssl.SSLPeerUnverifiedException: No peer certificate

I did this solution:
The correct behavior is to reject unknown certificates unless you explicitly configure it to accept all certificates.
Follow these steps:
- Uncheck HttpUtils2 library
- Add HttpUtils2 modules (from http://www.b4x.com/android/forum/threads/httputils2-web-services-are-now-even-simpler.18992)
- Check StringUtils and Http libraries
- Change hc.Initialize in HttpUtils2Service to hc.InitializeAcceptAll

Now the HttpJob is success with j.success = true ... not really.

Because on the [WebApp Server] there is a filter srvr.AddFilter("/login/members/*", "MembersFilter", False)
the B4A application HttpJob return success = true but with in j.GetString the source of the "/index.html". this the welcome page with no filter. And the file is not uploaded.

Any idea ...
 

Fabrice La

Active Member
Licensed User
Longtime User
B4X:
Sub cc_Result (Success As Boolean, Dir As String, FileName As String)
    Log(Success & " " & Dir & " :" & FileName & ":")
    If Success Then
'        Dim j As HttpJob
        Dim out As OutputStream
        out.InitializeToBytesArray(0)
        Dim In As InputStream = File.OpenInput(Dir, FileName)
        File.Copy2(In, out)
        Dim lastSlash As Int = FileName.LastIndexOf("/")
        If lastSlash > -1 Then
            FileName = FileName.SubString(lastSlash + 1)
        End If
        fichier = FileName
        Dim su As StringUtils
        Dim j As HttpJob
        j.Initialize("file", Me)
        link = link & spbox.SelectedItem & "/"
        j.PostBytes(link & "?type=file&name=" & su.EncodeUrl(FileName, "UTF8"), _
            out.ToBytesArray)
    End If
End Sub

I did not change the base code used in the example FileClientB4A
 
Upvote 0

Fabrice La

Active Member
Licensed User
Longtime User
My question is
Why the HttpJob return success = true with in j.GetString there is the source code of the "/index.html" (this the welcome page) and the file (that we try to upload) is not uploaded?
 
Upvote 0

Fabrice La

Active Member
Licensed User
Longtime User
Thanks to give me some information on how the Job.Success is working.

How can I resolve my problem ? Upload file from B4A to B4J server ? Or find what is wrong ?
 
Upvote 0

Fabrice La

Active Member
Licensed User
Longtime User
I am using the filter to avoid non-registred user to go to the member webside. Exactly like your example.
 
Upvote 0

Fabrice La

Active Member
Licensed User
Longtime User
Now I do use an error:
B4X:
resp.SendError(500, "Connection not permitted")

And now the B4A appli can not upload the file and return the error "Connection not permitted"

How I can upload a file in the server ?
 
Upvote 0
Top