B4J Question HTTP Post [SOLVED]

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
 
Last edited:

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: 113
Upvote 0

aeric

Expert
Licensed User
Longtime User
Try adding HU2_ACCEPTALL

1714066882750.png

The same case happened.
 
Upvote 0

moore_it

Well-Known Member
Licensed User
Longtime User
the last word

using this code

B4X:
Dim sb As StringBuilder
    sb.Initialize
    sb.Append("POST /hapld/tos/kdwhapltos HTTP/1.1" & CRLF)
    sb.Append("Content-type: multipart/mixed; boundary=BOUNDARY" & CRLF)
    sb.Append("Host: www.pld-certify.ups.com" & CRLF)
    sb.Append("Content-length: "&(sb.Length+21)& CRLF)
    sb.Append("--BOUNDARY" & CRLF)  
    sb.Append("Content-type: application/x-www-form-urlencoded" & CRLF)
    sb.Append("Content-length: "&78&CRLF)
    sb.Append(CRLF)
    sb.Append("AppVersion=1.0&AcceptUPSLicenseAgreement=Yes&ResponseType=application/x-ups-pld&VersionNumber=V4R1&UserId=" & data(4) & "&Password=" & data(5)  & CRLF)
    sb.Append(CRLF)
    sb.Append("--BOUNDARY" & CRLF)
    sb.Append("Content-type: application/x-ups-binary" & CRLF)
    sb.Append("Content-length: " & File.Size(path,filename) & CRLF)
    sb.Append(CRLF)
   
    sb.Append(ff)
   
    sb.Append(CRLF)
    sb.Append("--BOUNDARY--" & CRLF)
   
    If File.Exists(File.DirTemp,"ups") Then
        File.Delete(File.DirTemp,"ups")
    End If
    File.WriteString(File.DirTemp,"ups",sb.ToString)
    Try
        okHTTP.InitializeAcceptAll("HTTPSOK")
        Dim res As OkHttpRequest
        res.InitializePost(data(3),File.OpenInput(File.DirTemp,"ups"),File.OpenInput(File.DirTemp,"ups").BytesAvailable)
        res.SetContentType("Content-type: multipart/mixed; boundary=BOUNDARY")
        okHTTP.Execute(res,0)
    Catch
        ListView2.Items.Add(Chr(0xF071)&" Errore nell'invio del file !")
        If controller <> "" Then
'            ControlMail(action,controller,Chr(0xF071)&BytesToString(out.ToBytesArray, 0, out.ToBytesArray.Length, "utf8"))
        End If
        Log(LastException.Message)
    End Try

have this result

1715065988905.png

this return is useful for error catching ...

with this code

B4X:
    Try
        Dim fd As MultipartFileData
        fd.Initialize
        fd.Dir = path
        fd.FileName = filename
        fd.ContentType = "application/x-ups-binary"
   
        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)
        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

have this result

1715066168537.png

job.getstring return blank.

I need to use another programming language.

Thanks for help.
 
Upvote 0

moore_it

Well-Known Member
Licensed User
Longtime User
yes confirm !
have a response in any case if all right or for warnings errors or for fatal errors
 
Upvote 0
Top