B4J Question HTTP Post

moore_it

Well-Known Member
Licensed User
Longtime User
Hi all,

how i do for posting a file on https server ?

I try with Httpjob but not work this is the errormessage.

javax.net.ssl.SSLPeerUnverifiedException: peer not authenticated

this is my code ...

B4X:
mHTTP.Initialize("HTTP", Me)
        mHTTP.Username = data(4)
        mHTTP.Password = data(5)
        mHTTP.PostString(data(3),msg)

where: data(4) = username, data(5) = password, data(3) = server address, msg = string data
 

moore_it

Well-Known Member
Licensed User
Longtime User
1713521205232.png
 
Upvote 0

moore_it

Well-Known Member
Licensed User
Longtime User
See it's connected and respond

How i do for post appversion ????

I tried res.setheader but not work
 
Upvote 0

aeric

Expert
Licensed User
Longtime User
I don't think I can help further.

try:
B4X:
Sub UploadFile
    Try
        Dim fd As MultipartFileData
        fd.Initialize
        fd.Dir = "C:\B4X"
        fd.FileName = "sample.txt"
        fd.ContentType = "multipart/mixed; boundary=BOUNDARY"
     
        Dim Params1 As Map
        Params1.Initialize
        Params1.Put("AppVersion", "1.0")
        Params1.Put("AcceptUPSLicenseAgreement", "YES")
        Params1.Put("ResponseType", "application/x-ups-pld")
        Params1.Put("VersionNumber", "V4R1")
        Params1.Put("UserId", "PLDDSTEST")
        Params1.Put("Password", "PLDDSTEST")

        Dim File1 As List
        File1.Initialize
        File1.Add(fd)
     
        Dim job As HttpJob
        job.Initialize("", Me)
        job.PostMultipart("https://www.pld-certify.ups.com/hapld/tos/kdwhapltos", Params1, File1)
        'job.PostMultipart("https://www.pld-certify.ups.com/hapld/tos/kdwhapltos", Null, File1)
        Log("Uploading file...")
        Wait For (job) JobDone(job As HttpJob)
        If job.Success Then
            Log("Success: " & job.GetString)
        Else
            Log("Failed: " & job.ErrorMessage)
        End If
    Catch
        Log("Error: " & LastException.Message)
    End Try
    job.Release
End Sub
 
Upvote 0

OliverA

Expert
Licensed User
Longtime User
What versions of Java are each of you using? Older versions may not have updated certificates for validation.
 
Upvote 0

OliverA

Expert
Licensed User
Longtime User
Using the code snippet provided by @aeric in post #25 above, I was able to successfully upload a test file using JDK 18.0.1, JDK 14.0.1, and JDK 11.0.1. I even used a version 8 SDK provided by OpenLogic. I even copied my version of JDK 14 to the Program Files (x86) directory as you did, and it still worked.

It must be something on your end. It could be the jHttp library that you are including. That library is not included anymore with newer B4J versions and may conflict with the existing OkHttp/jOKHttpUtils2 libraries.

Note:
I'm attaching the project that works for me (pretty much what @aeric posted with the included corrections shown in post#25)

Links:
Post # 25: https://www.b4x.com/android/forum/threads/http-post.160513/post-985938

OpenLogic JDK 8: https://www.openlogic.com/openjdk-d...arget_id=391&field_java_package_target_id=396
OpenJDK 11.0.1: https://www.b4x.com/b4j/files/java/jdk-11.0.1.zip
OpenJDK 14.0.1: https://www.b4x.com/b4j/files/java/jdk-14.0.1.zip
OpenJDK 18.0.1: Download link is not available anymore. Originally from https://www.b4x.com/android/forum/threads/update-openjdk.140167/post-887809
 

Attachments

  • PLDSP_Test.zip
    9.4 KB · Views: 19
Upvote 0

aeric

Expert
Licensed User
Longtime User
Try adding HU2_ACCEPTALL

1714066882750.png

The same case happened.
 
Upvote 0
Top