Android Question OKHTTP problem

Discussion in 'Android Questions' started by grafsoft, Aug 23, 2015.

  1. grafsoft

    grafsoft Well-Known Member Licensed User

    Hi,

    I used HttpResponse.getstring. OkHttpResponse does not provide this anymore. What is the best replacement?

    Code:
    Sub HttpClient1_ResponseSuccess (Response As OkHttpResponse, TaskId As Int)
       inp.Close
       
    Dim s,s2 As String
       
    ' Getstring does not exist anymore
       s=Response.GetString("UTF8")
     
  2. fixit30

    fixit30 Active Member Licensed User

    Erel likes this.
  3. Erel

    Erel Administrator Staff Member Licensed User

    Don't use Response.GetString. It is deprecated and will fail in release mode in Android 4+. Use HttpUtils2 instead.
     
  4. grafsoft

    grafsoft Well-Known Member Licensed User

    OK, thanks. But now every upload fails, server error 500. I use uploadform.asp.
     
  5. Erel

    Erel Administrator Staff Member Licensed User

    Please do not make duplicate posts.

    It is impossible to say why it fails without seeing the code and the previous code that worked.
     
  6. grafsoft

    grafsoft Well-Known Member Licensed User

    Sorry ...

    Code:
    Sub startit
       

        
    Dim req As OkHttpRequest
        
    Dim size As Long
        
    Dim fname As String
    ' "Files" is the list of files to upload
        icount=icount+1
        
    If icount > files.size Then
            
    Return
        
    End If
        fname=files.Get(icount-
    1)
        
    Log ("startit " & fname)
        
    Try

        size = 
    File.size(Main.outdir, fname)
        
    Log (size)
        Main.prot.add (
    "upload " & fname)
        
    Log (size)
        
    Log (fname)
        label1.Text=fname & 
    " (" & size & ")"
        inp= 
    File.OpenInput(Main.outdir,fname)
        req.InitializePost(Main.hostname & 
    "uploadform.asp", inp, size)
        HttpClient1.Execute(req, 
    1)
        uploadrunning=
    True
        
    Catch
            
    Log (LastException.Message)
            Main.prot.Add (
    LastException.Message)
            startit
        
    End Try
    End Sub


    Sub HttpClient1_ResponseError (Response As OkHttpResponse, Reason As String, StatusCode As Int, TaskId As Int)
       
    ' always says "Error"
        Log("Error " & Reason)
        
    Log (Response)
        
    Log (StatusCode)
        
    Log (TaskId)
        
    ' Msgbox (Response,Reason)
        icount=icount-1
        startit
    End Sub

    Sub HttpClient1_ResponseSuccess (Response As OkHttpResponse, TaskId As Int)
       
    ' No need to explain this code, it never comes here.
        inp.Close
        
    Dim s,s2 As String
        
    ' s=Response.GetString("UTF8")
        Log ("Responsesuccess: " & icount & " " & s)
        
    If icount<1 Then 
            icount=
    1
        
    End If
        s2=files.Get(icount-
    1)
        
    Log ("sucess=" & s2)
    Log ("sucess=" & s2)
            hjob.Download (Main.hostname & 
    "rename.php?from=" & s & "&to=" & Main.projectnumber & "_" & s2)
    End Sub


    [Code]
     

    Attached Files:

  7. Erel

    Erel Administrator Staff Member Licensed User

    I highly recommend you to remove the HttpClient code. Use only HttpUtils2. It will be simpler.
     
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