B4i Library [class] HttpUtils2

Latest version is available here: https://www.b4x.com/android/forum/threads/b4x-okhttputils2-ihttputils2-httputils2-source-code.82632/

B4i implementation of HttpUtils2: http://www.b4x.com/android/forum/threads/httputils2-web-services-are-now-even-simpler.18992/#content

SS-2014-11-06_16.36.36.png


V2.10 is attached. See post #9 for more information.
Note that it requires B4i v2+. You can delete HttpJob.PostMultipart if you need to work with previous versions.
 

Attachments

  • HttpUtils2.zip
    4.9 KB · Views: 1,033
Last edited:

jaraiza

Active Member
Licensed User
Longtime User
Hi,

I'm having some trouble with this class. Sometimes the Job is not released and keeps entering the same section. I went to HttpJob class and found the Release Sub is empty. I can even assign the name again after it's released.
B4X:
JName = Job.JobName
Job.Release
JName = Job.JobName
That code doesn't trigger any error.

Thanks!
 

davepamn

Active Member
Licensed User
Longtime User
Where should I copy the httpjob.bas and httpUtils2Service.bas file so it is shared by all projects?

Do I have to copy this file into every project that uses httpUtils2?

When I tried to add them into the project it said these two files exit, so I didn't added them

I am getting a red variable for

dim jobLogin as httpjob

I have selected the ihttp library

the error message is "you are missing a library reference"

I need to httpjob.bas and httpUtils2Service.bas as modules.

I created a folder call "shared modules" and copied httpjob.bas and httputils2service.bas into it.

I changed tools->configure paths->Shared Modules to point to the directory

I am still getting the library reference error
 
Last edited:

davepamn

Active Member
Licensed User
Longtime User
Resolved

I added httpjob.bas and httputils2service.bas as existing modules from the shared module directory
I can see the modules in the modules tab, (this time there was not a request to override)
The code compiled.
 

imbault

Well-Known Member
Licensed User
Longtime User
Hi Erel, I think there is a bug in iHttputils, concerning :

Explication, I've create an entry point in a code module:
Tools:
B4X:
Sub InvokeWS(cUrl As String, WsName As String, Jobname As String, ParamValue() As WSParam, DoneAct As String,timeout As Int, message As String  )
Dim jobtest As HttpJob
Dim endPoint As String
Dim requestSoapXML As String
Dim i As Int
Main.hdShow.ProgressDialogShow(message)
Sleep(100)

    endPoint = cUrl

    requestSoapXML = _
        "<soap:Envelope xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:soap='http://schemas.xmlsoap.org/soap/envelope/'>" & _
        "<soap:Body>" & _
        "<" & WsName & " xmlns='http://patrick.imbault.org/'>" & CRLF
        For i = 0 To ParamValue.Length -1
            requestSoapXML = requestSoapXML & "<" & ParamValue(i).ParamName & ">" & ParamValue(i).ParamValue & "</" & ParamValue(i).ParamName & ">" & CRLF
        Next
        requestSoapXML = requestSoapXML & "</" & WsName & ">" & _
        "</soap:Body>" & _
        "</soap:Envelope>"

    Log(requestSoapXML )

    jobtest.Initialize(Jobname,DoneAct)
    jobtest.PostString ( endPoint, requestSoapXML)
    jobtest.GetRequest.SetHeader("SOAPAction", "http://patrick.imbault.org/"  & WsName)
    jobtest.GetRequest.SetHeader("Content-Type", "text/xml; charset=utf-8")
    jobtest.GetRequest.timeout = timeout



End Sub

When I call InvokeWS from another code module:

import code module
B4X:
Sub BookJob(cJob As String,cBook As String)
Dim  UserWs(4) As WSParam

UserWs(0).ParamName ="username"
UserWs(0).ParamValue =Main.SmileLogon.userid
UserWs(1).ParamName ="deviceid"
UserWs(1).ParamValue =Main.SmileLogon.deviceid
UserWs(2).ParamName ="jobid"
UserWs(2).ParamValue =cJob
UserWs(3).ParamName ="status"
UserWs(3).ParamValue = cBook

tools.InvokeWS(Main.WS_Url,Main.WS_get_book_job,"bookjob",UserWs,"import",20000,"Fetching and Booking Job " & cJob & " ...")

End Sub

Sub JobDone (job1 As HttpJob)
    Dim sRet As String

    If job1.JobName = "checkjobs" Then
        sRet = tools.GetWsresult(job1,Main.WS_get_pending_jobs,"checkjobs")
        If sRet.Length>0 AND sRet <> "-1" Then
            affichejobs(sRet)
        End If
    Else If job1.JobName="bookjob" Then
        sRet = tools.GetWsresult(job1,Main.WS_get_book_job,"bookjob")
        If sRet.Length>0 AND sRet <> "-1" Then
            addjob(sRet)
        End If
    End If
    Main.hdShow.ProgressDialogHide
    job1.Release
End Sub
Complete Sub of HttpJob should call JobDone in the import code module
B4X:
'Called by the service when job completes
Public Sub Complete (res1 As HttpResponse)
    res = res1
     CallSub2(target, "JobDone", Me)
End Sub

In spite of calling JobDone in the import code module (in that case), it fires an error in the CallSub2 which doesn't find apparently the import code module,

I had to modify it like this, which in not very good:

B4X:
'Called by the service when job completes
Public Sub Complete (res1 As HttpResponse)
    res = res1
    If target="setup" Then
        CallSub2(setup,"JobDone", Me)
    Else If target="import" Then
        CallSub2(import,"JobDone", Me)
    End If

    'bug here
    'CallSub2(target, "JobDone", Me)
End Sub

Many thanks

Patrick
 
Last edited:

Erel

B4X founder
Staff member
Licensed User
Longtime User
V2.10 was uploaded to the first post. It adds support for multipart POST requests.

For example:
B4X:
Dim Job As HttpJob
Job.Initialize("job", Me)
Dim fd As MultipartFileData
fd.Initialize
fd.Dir = File.DirAssets
fd.FileName = "somefile.dat"
fd.KeyName = "upfile"
fd.ContentType = "application/octet-stream"
Job.PostMultipart("http://192.168.0.0/FileUpload", CreateMap("Key1": "Value1", "Key2": "Value2"), Array(fd))
 

Indy

Active Member
Licensed User
Longtime User
Hi Erel,

When posting the string, is there a limit to the size of the string? I get an error when trying to upload a ~300K jpg file. I'm encoding the bytes to 64 bits. If I post a small file 1 or 2k it works fine. Problem when I try to view the string in the log file is the post string gets truncated so I cannot see the entire sent http post.

I used the equivalant version of this library in my Android project and that works ok with jpgs. I'm now converting my app to iOS but stuck on this final bit.

Thanks
 

MarcoRome

Expert
Licensed User
Longtime User
V2.10 was uploaded to the first post. It adds support for multipart POST requests.

For example:
B4X:
Dim Job As HttpJob
Job.Initialize("job", Me)
Dim fd As MultipartFileData
fd.Initialize
fd.Dir = File.DirAssets
fd.FileName = "somefile.dat"
fd.KeyName = "upfile"
fd.ContentType = "application/octet-stream"
Job.PostMultipart("http://192.168.0.0/FileUpload", CreateMap("Key1": "Value1", "Key2": "Value2"), Array(fd))

I dont see PostMultipart ( Rel HttpUtils 2.10 ). Wrong ??
 

valentino s

Active Member
Licensed User
Longtime User
I'm a newbie. Sorry for the silly question.
How can I install the library ?
I don't find .xml .h or similar files, so I can simply put the files unzipped in

C:\Program Files (x86)\Anywhere Software\B4i\Libraries

Thanks in advance
Valentino
 
Top