1. *** New version of B4J is available ***
    B4J v7.8
    Dismiss Notice

B4i Library [class] HttpUtils2

Discussion in 'iOS Libraries' started by Erel, Nov 6, 2014.

  1. Erel

    Erel Administrator Staff Member Licensed User

    Attached Files:

    Last edited: Aug 9, 2017
  2. jaraiza

    jaraiza Active Member Licensed 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.
    Code:
    JName = Job.JobName
    Job.Release
    JName = Job.JobName
    That code doesn't trigger any error.

    Thanks!
     
  3. Erel

    Erel Administrator Staff Member Licensed User

    It is not related. It is empty as it is not required in B4i. It is kept for API compatibility with B4A/B4J.
     
  4. davepamn

    davepamn Active Member Licensed 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: Dec 12, 2014
  5. davepamn

    davepamn Active Member Licensed 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.
     
  6. imbault

    imbault Well-Known Member Licensed User

    Hi Erel, I think there is a bug in iHttputils, concerning :

    Explication, I've create an entry point in a code module:
    Tools:
    Code:
    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
    Code:
    Sub BookJob(cJob As String,cBook As String)
    Dim  UserWs(4As 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
    Code:
    '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:

    Code:
    '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: Mar 23, 2015
  7. Erel

    Erel Administrator Staff Member Licensed User

    The TargetModule parameter should be an object, not a string. You should pass Me instead of "import" and change the type from String to Object.
     
  8. imbault

    imbault Well-Known Member Licensed User

    You're right Erel, Thanks

    Patrick
     
  9. Erel

    Erel Administrator Staff Member Licensed User

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

    For example:
    Code:
    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))
     
    tamayo461 likes this.
  10. Indy

    Indy Active Member Licensed 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
     
  11. Erel

    Erel Administrator Staff Member Licensed User

    Please start a new thread for this and post the code that doesn't work.
     
  12. Alberto Iglesias

    Alberto Iglesias Well-Known Member Licensed User

    This class not support progress download monitoring?

    Do you have another class or native code to do this?

    i´m working in a app to download videos from youtube, but I can see the downloaded %

    Thanks.

    Alberto Iglesias
     
  13. Douglas Farias

    Douglas Farias Expert Licensed User

  14. Erel

    Erel Administrator Staff Member Licensed User

    OkHttp is a B4A library, not a B4i library. This class depends on iHttp library.
     
    Douglas Farias likes this.
  15. MarcoRome

    MarcoRome Expert Licensed User

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

    Erel Administrator Staff Member Licensed User

    It is in HttpJob class.
     
  17. MarcoRome

    MarcoRome Expert Licensed User

    Ok. Thank's Erel. Do you think add this also in library httutils2 ?
     
  18. MarcoRome

    MarcoRome Expert Licensed User

    But this isnt in HttpJb class B4A ? right ?
     
  19. Erel

    Erel Administrator Staff Member Licensed User

    No. It is a B4i class. However you can copy the sub to B4A HttpJob and it will work.
     
    MarcoRome likes this.
  20. valentino s

    valentino s Active Member Licensed 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
     
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice