Android Question Sub JobDone (job As HttpJob), Error 404

angel

Member
Licensed User
Longtime User
Hello

I send a list of integers to a webservice, when this list exceeds a lengt I get the 404 error in the jobDone

B4X:
Sub BSendIdHisDoc
    Dim map As Map
    Dim llista As List
    map.Initialize
    llista.Initialize
    llista.Clear
   
    llista = DBUtils.ExecuteMemoryTable(Main.SQL,"SELECT DISTINCT id_mnt_punto FROM his_mnt_operacion_punto WHERE id_mnt_punto <> 0",Null,0)
    'llista = DBUtils.ExecuteMemoryTable(Main.SQL,"SELECT DISTINCT id_mnt_punto FROM his_mnt_operacion_punto WHERE id_mnt_punto = 10868",Null,0)
    Dim llistaIds As List
    llistaIds.Initialize
    Dim ids As List
    ids.Initialize
   
    Dim jsonBuilder As StringBuilder
    jsonBuilder.Initialize()

'  
'    jsonBuilder.Append("[")
'    For i=0 To llista.Size-1
'        ids.Add(llista.Get(i))
'        map = CreateMap("IDHisDoc": Null)
'  
'        Dim str(0) As String = llista.Get(i)
'        jsonBuilder.Append("{""IDHisDoc"":").Append("""" & str(0) & """").Append("},")
'    Next
'  
'    jsonBuilder.Append("]")
   
    jsonBuilder.Append("[{""IDHisDoc"":""27740""}, {""IDHisDoc"":""27739""}, {""IDHisDoc"":""20244""}, {""IDHisDoc"":""29386""}, {""IDHisDoc"":""16035""}, {""IDHisDoc"":""6322""}, {""IDHisDoc"":""28624""}, {""IDHisDoc"":""10958""}, {""IDHisDoc"":""21074""}, {""IDHisDoc"":""682""}, {""IDHisDoc"":""21045""}, {""IDHisDoc"":""29343""}, {""IDHisDoc"":""10868""}, {""IDHisDoc"":""6323""}, {""IDHisDoc"":""10869""}, {""IDHisDoc"":""1772""}, {""IDHisDoc"":""683""}, {""IDHisDoc"":""16037""}, {""IDHisDoc"":""21071""}, {""IDHisDoc"":""22590""}, {""IDHisDoc"":""29344""}, {""IDHisDoc"":""28625""}, {""IDHisDoc"":""5613""}, {""IDHisDoc"":""6324""}, {""IDHisDoc"":""29345""}, {""IDHisDoc"":""16038""}, {""IDHisDoc"":""22589""}, {""IDHisDoc"":""684""}, {""IDHisDoc"":""28626""}, {""IDHisDoc"":""21073""}, {""IDHisDoc"":""29374""}, {""IDHisDoc"":""5614""}, {""IDHisDoc"":""6325""}, {""IDHisDoc"":""10950""}, {""IDHisDoc"":""5615""}, {""IDHisDoc"":""21075""}, {""IDHisDoc"":""29346""}, {""IDHisDoc"":""16043""}, {""IDHisDoc"":""28627""}, {""IDHisDoc"":""554""}, {""IDHisDoc"":""6326""}, {""IDHisDoc"":""5616""}, {""IDHisDoc"":""28628""}, {""IDHisDoc"":""29347""}, {""IDHisDoc"":""10956""}, {""IDHisDoc"":""7827""}, {""IDHisDoc"":""21076""}, {""IDHisDoc"":""16044""}, {""IDHisDoc"":""6327""}, {""IDHisDoc"":""28629""}, {""IDHisDoc"":""10952""}, {""IDHisDoc"":""16046""}, {""IDHisDoc"":""29348""}, {""IDHisDoc"":""21077""}, {""IDHisDoc"":""2368""}]")

'    Dim json As JSONGenerator
'    json.Initialize2(llistaIds)
'    json.ToString
    jsonBuilder.ToString
    Log(jsonBuilder.ToString)
   
    If Codi.CheckWiFi(True) Then
        Dim job As HttpJob
        job.Initialize("getImagePoint", Me)
        job.Download2(Main.webserver&"/ws.asmx/getImagePoint", Array As String("jSonPoints", jsonBuilder.ToString))
        job.GetRequest.TimeOut = 5000
   
       
    Else
        ' Error si no hi ha connexió
        ToastMessageShow("Error descargar imagenes", True)
        Sleep(3000)
    End If
   
End Sub

B4X:
Sub JobDone (job As HttpJob)
    'If job.Success Then
        Try
            ' Obtenim les fotos dels punts d'inspecció
            Dim jsonParser As JSONParser
            jsonParser.Initialize(job.GetString)
'            Dim mResponse As Map
'            mResponse.Initialize
           
             'If mResponse.IsInitialized Then
                'mResponse = jsonParser.NextArray
                Main.SQL.ExecNonQuery("DELETE FROM cus_guardar_imatges")
                Dim quotes As List = jsonParser.NextArray
               
                'For Each quot As Map In quotes
                DBUtils.InsertMaps(Main.SQL, "cus_guardar_imatges", quotes, False)
                Log("DOWNLOAD IMAGES SUCCESS")
                'Next
            'End If
           
        Catch
            Log(LastException)
        End Try
    'End If
   
    job.Release
    ProgressDialogHide
End Sub


If in the list jsonBuilder.Append removed the last record, it works fine and I download the images in base64 What could be the problem?

Thank you.
 

Attachments

  • error1.png
    error1.png
    111.5 KB · Views: 212

angel

Member
Licensed User
Longtime User
Not use Get

the code of web service

B4X:
    <WebMethod()>
    <ScriptMethod(ResponseFormat:=ResponseFormat.Json, UseHttpGet:=False)>
    Public Sub getImagePoint(jSonPoints As String)

        Dim dades2 As String = ""

        Try
            If connecta() Then

                Dim listOfPoints As New List(Of Points)
                listOfPoints = JsonConvert.DeserializeObject(Of List(Of Points))(jSonPoints.Replace(":[", ":").Replace("]}", "}"))
                Dim statement As String
                Dim qPoints As New Query
                Dim idPoint As Integer

                Dim list As List(Of Dictionary(Of String, Object)) = New List(Of Dictionary(Of String, Object))
                list.Clear()

                For Each point As Points In listOfPoints
                    idPoint = point.IDHisDoc
                    statement = String.Format("SELECT id_mnt_punto, Pathimagen, cus_Valor4 FROM cfg_mnt_punto WHERE id_mnt_punto = '{0}'", idPoint)


                    If qPoints.ExecQuery(statement) Then
                        Dim dr As DataRow = qPoints.dt.NewRow()

                        dr("id_mnt_punto") = qPoints.dt.Rows(0)("id_mnt_punto")
                        dr("Pathimagen") = qPoints.dt.Rows(0)("Pathimagen")

                        If qPoints.dt.Rows(0)("Pathimagen").Equals(DBNull.Value) Then
                            dr("Pathimagen") = "nullvalue"
                        End If

                        Try


                            If qPoints.dt.Rows(0)("Pathimagen") Is DBNull.Value Or qPoints.dt.Rows(0)("Pathimagen") = "" Or dr("Pathimagen").Equals("nullvalue") Then
                                'dr("Pathimagen") = ""
                                'dr("cus_Valor4") = ""
                            Else
                                dr("Pathimagen") = qPoints.dt.Rows(0)("Pathimagen")
                                dr("cus_Valor4") = ConvertFileToBase64(qPoints.dt.Rows(0)("Pathimagen"))
                            End If

                            Dim d As Dictionary(Of String, Object) = New Dictionary(Of String, Object)(qPoints.dt.Columns.Count)
                            For i As Integer = 0 To qPoints.dt.Columns.Count - 1
                                If qPoints.dt.Rows.Item(0).ItemArray.GetValue(1) IsNot DBNull.Value Then
                                    d(qPoints.dt.Columns(i).Caption) = dr(i)
                                End If
                            Next
                            list.Add(d)
                            ' Eliminem registres null de la llista avans de passar a JSON.
                            list.RemoveAll(Function(dades) dades.Count = 0)
                            list.RemoveAll(Function(nopath) nopath.Item("Pathimagen").Equals(""))


                            Dim j As JavaScriptSerializer = New JavaScriptSerializer()
                            j.MaxJsonLength = 90000000
                            dades2 = JsonConvert.SerializeObject(list.ToArray(), Formatting.Indented)
                          
                            dades2 = dades2.Replace("\\", "\")

                        Catch ex As Exception
                            LogTXT(ex.Message + dr("Pathimagen"))
                            dades2 = JsonConvert.SerializeObject(list.ToArray(), Formatting.Indented)
                            dades2 = dades2.Replace("\\", "\")
                        End Try
                    End If
                Next
            End If

        Catch ex As Exception
            dades2 = "* Error " & ex.Message
        End Try
        Context.Response.Write(dades2)
    End Sub
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
Upvote 0

angel

Member
Licensed User
Longtime User
check the lenght

our string is 1412 characters long. ' NOT WORK

Delete last record
Your string is 1385 characters long. ' WORK OK

It's possible the max is 1400?
 
Upvote 0

angel

Member
Licensed User
Longtime User
He tried removing spaces and going below <1400 and it does not work. It seems more problem of the amount of id's "IDHisDoc"
 
Upvote 0

angel

Member
Licensed User
Longtime User
I am trying to use job.PostString that allows 5Mb but I get the error "Missing the pair: jSonPoints.

B4X:
job.PostString(Main.webserver&"/ws.asmx/getImagePoint", "{""IDHisDoc"":""10868""}")
 
Upvote 0

OliverA

Expert
Licensed User
Longtime User
B4X:
job.PostString(Main.webserver&"/ws.asmx/getImagePoint", "jSonPoints=" & jsonBuilder.ToString)
 
Upvote 0
Top