B4J Question OkHttp - HTTP/2 support

Discussion in 'B4J Questions' started by JanPRO, Jan 11, 2019.

  1. JanPRO

    JanPRO Well-Known Member Licensed User

    Hi,
    However, when I request the following test api: https://http2.pro/api/v1 I get the result, that HTTP/2 is not supported. So my question now, does the latest B4J OkHttp library really support HTTP/2?

    Jan
     
  2. KMatle

    KMatle Expert Licensed User

    Your exact code?
     
  3. JanPRO

    JanPRO Well-Known Member Licensed User

    Hi,

    it's just a simple Get request:

    Code:
    Sub TestHttp2
        
    Dim H As HttpJob
        H.Initialize(
    "",Me)
        H.Download(
    "https://http2.pro/api/v1")
        
        
    Wait For (H) JobDone(J As HttpJob)
        
        
    Log(J.GetString)
    End Sub
    Jan
     
  4. inakigarm

    inakigarm Well-Known Member Licensed User

    You'll have to use http source class modules ("HttpJob.bas" "HttpUtils2Service.bas") not the jokhttputils library () and in the "HttpUtils2Service.bas" change the hc initialization to
    Code:
    hc.InitializeAcceptAll("hc")
    (source modules: https://www.b4x.com/android/forum/t...putils2-httputils2-source-code.82632/#content

    hc.InitializeAcceptAll skips the certificate verification step

    With that, this is the result:

    Code:
    Dim H As HttpJob
       H.Initialize(
    "",Me)
       H.Download(
    "https://http2.pro/api/v1")
      
       
    Wait For (H) JobDone(J As HttpJob)
       
    If J.Success Then
           
    Log(J.GetString)
       
    Else
           
    Log(J.ErrorMessage)
       
    End If
    {"http2":0,"protocol":"HTTP\/1.1","push":0,"user_agent":"okhttp\/3.5.0"}

    See also: https://www.b4x.com/android/forum/t...liente-to-server-using-ssl.94727/#post-599293
     
    JanPRO likes this.
  5. JanPRO

    JanPRO Well-Known Member Licensed User

    Thank you, but I don't have any problem with the SSL certificate.
    This question is about the protocol used by OkHttp. In your response
    you can see that Http 1.1 was used, when you open the Api url in a modern browser you will see that the value for http2 becomes 1.

    Jan
     
  6. DonManfred

    DonManfred Expert Licensed User

    Based on this SO.
    best is to use java 9 i guess. But i don´t know if that helps.
     
    JanPRO and inakigarm like this.
  7. inakigarm

    inakigarm Well-Known Member Licensed User

    Yes, I mirsread your first post ;-)
     
    JanPRO likes this.
  8. DonManfred

    DonManfred Expert Licensed User

    I just searched for java 9 and realized that b4j can work with openjava 11
    See https://www.b4x.com/b4j.html#installation

    I just configured my b4j (V7.0) to use the open java 11. and tried the code above

    Code:
    Dim H As HttpJob
        H.Initialize(
    "",Me)
        H.Download(
    "https://http2.pro/api/v1")
     
        
    Wait For (H) JobDone(J As HttpJob)
        
    If J.Success Then
            
    Log(J.GetString)
        
    Else
            
    Log(J.ErrorMessage)
        
    End If
    This is the result:
    As a fazit i would suggest to switch to OpenJDK 11
     
    Last edited: Jan 12, 2019
    Erel, OliverA, JanPRO and 1 other person like this.
  9. JanPRO

    JanPRO Well-Known Member Licensed User

    Awesome, thank you very much DonManfred :)
     
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