Spanish Error {"";[The input was not valid."]}

Miguel Santillan

Member
Licensed User
Quisiera obtener informacion de un servidor, al cual le debo pasar la dirección de URL y el método solamente.
Hasta ahora lo venia trabajando con JSON.POSTSTRING a un servidor PHP y comando SQL sin problemas (o sea sin métodos)

Me devuelve el error Error {"";[The input was not valid."]} y es muy probable que no esté pasando datos correctamente.
Alguno me podría pasar una sugerencia con respecto a este tipo de poststring o tal vez hay que usar otro comando.

Paso parte del código.

Poststrin con metodo:
Sub Procesa_Subida
    Dim Cantidad_registros As Int
    Dim Registros As List
    Dim Job As HttpJob
    Dim Jobname As String
    Dim json As JSONParser
    Dim codigo_cliente As String
    Dim orden_cliente As String
    Dim nombre_cliente As String
    Dim domicilio_cliente As String
    Dim zona_cliente As Int
    Dim telefono_cliente As String
    Dim saldo_cliente As String
    Dim dias_cliente As Int
    Dim credito_cliente As Int
    Dim habilitado_cliente As Int
    Dim rubro_cliente As String
    Dim x_fecha1 As String
    Dim x_fecha2 As String
    Dim Fecha_hoy As String
    Dim Hora_hoy As String
    DateTime.DateFormat = "yyyy-MM-dd"
    Fecha_hoy = DateTime.Date(DateTime.Now)
    Hora_hoy = DateTime.Time(DateTime.Now)
    Dim X_Dias As Int
    ProgressDialogHide
    Job.JobName = "Procesa Clientes"
    Job.Initialize(Jobname, Me)
    Query = $"{"metodo":"ejecutar_query","parametros":["","CLIENTES_P_WEB","","","","","","","",""]}"$
    Job.PostString("https://xxxxxx.vvvvv.com:1111/ffffff/?key=123", Query)
    wait for(Job) JobDone(Job As HttpJob)
    
    If Job.Success Then
        Dim res As String
        res = Job.GetString
        Log("Respuesta del Servidor: " & res)
        Dim parser As JSONParser
        parser.Initialize(res)
        Dim m As Map
        m = parser.NextObject
        Registros = m.Get("recibidos")
        Cantidad_registros = Registros.Size
        If Registros.Size > 0 Then
            LblTipo.Text = "Actualizando Base"
            LblTipo.Color = Colors.Blue
            LblTipo.TextColor = Colors.Yellow
            For i = 0 To Registros.Size - 1
                m = Registros.Get(i)
                codigo_cliente    = m.Get("id_cliente")
                nombre_cliente    = m.Get("nombres")
                domicilio_cliente = m.Get("domicilio")
                'habilitado_cliente = m.Get("habilitado")
                SQL1.ExecNonQuery("INSERT INTO clientes(id_cliente, nombres, domicilio) VALUES('" & codigo_cliente & "','" & nombre_cliente & "','" & domicilio_cliente & "')")
                pgb1.Progress = i / Cantidad_registros * 100
                Porcentaje = i / Cantidad_registros * 100
                lblPercent.Text = Porcentaje
                lblPercent.Text = NumberFormat2(Porcentaje,0,2,2, False)
                Sleep(0)
            Next
            Sleep(0)
            Job.Release
        End If
    Else
        Msgbox("Error al conectar Base","Error")
        Activity.Finish
    End If
    
End Sub

Muchas gracias
Miguel
 

TILogistic

Expert
Licensed User
Longtime User
Query = $"{"metodo":"ejecutar_query","parametros":["","CLIENTES_P_WEB","","","","","","","",""]}"$
Job.PostString(" ", Query)

Puedes publicar como es la rutina en PHP, por que no veo en tu código si es un método GET o POST como debe llamarse.

Ver método Get con parámetros
 

TILogistic

Expert
Licensed User
Longtime User
Para generar el Json es mejor usar:
B4X:
    Dim parametros As List
    parametros.Initialize2(Array As String("","CLIENTES_P_WEB","","","","","","","",""))
   
    Dim JSONGenerator As JSONGenerator
    JSONGenerator.Initialize(CreateMap("metodo": "ejecutar_query", "parametros": parametros))

    Dim Query As String = JSONGenerator.ToPrettyString(2)
    Log(Query)

JSON:
{
  "metodo": "ejecutar_query",
  "parametros": [
    "",
    "CLIENTES_P_WEB",
    "",
    "",
    "",
    "",
    "",
    "",
    "",
    ""
  ]
}
 
Last edited:

Miguel Santillan

Member
Licensed User
Muchas gracias por tu respuesta.
Te comento, el servidor que me responde al método es de una empresa que da servicios a mi cliente y lo único que me ha informado es la URL y el método.
O sea no conozco el código del servicio. Lamentablemente.

Voy a tratar de conseguirlo.
Muchas gracias
 

Miguel Santillan

Member
Licensed User
Disculpame, no habi visto esta respuesta.


Dim parametros As List
parametros.Initialize2(Array As String("","CLIENTES_P_WEB","","","","","","","",""))

Dim JSONGenerator As JSONGenerator
JSONGenerator.Initialize(CreateMap("metodo": "ejecutar_query", "parametros": parametros))

Dim Query As String = JSONGenerator.ToPrettyString(2)
Log(Query)


Luego de hacer esto habria que ejecutar el Poststring u otro comando para conectarse ( me refiero a como quedaria lo que te paso a continuación de acuerdo a lo que está mas arriba.


Job.PostString("https://xxxxxx.vvvvv.com:1111/ffffff/?key=123", Query)
 

TILogistic

Expert
Licensed User
Longtime User
Por lo que veo en tu código es un método GET que rescata datos de cliente.

Prueba este código en forma separada y ve si trae datos o bien revisa el log error para saber cual fue:

Cambiar tu url:

B4X:
Public Sub TestURL
    Dim URL As String = "https://xxxxxx.vvvvv.com:1111/ffffff"
   
    Dim ListParametros As List
    ListParametros.Initialize2(Array As String("","CLIENTES_P_WEB","","","","","","","",""))
   
    Dim JSONGenerator As JSONGenerator
    JSONGenerator.Initialize2(ListParametros)
    Dim JsonParametros As String = JSONGenerator.ToString

    Dim Parameters() As String = Array As String ("key", 123, "metodo", "ejecutar_query", "parametros", JsonParametros)
    Wait For (GetURL(URL, Parameters)) Complete (DataResult As String)
    Log(DataResult)
   
End Sub

B4X:
Public Sub GetURL(URL As String, Parameters() As String) As ResumableSub
    Dim ResultURL As String
    Dim j As HttpJob
    Try
        j.Initialize("", Me)
        j.Download2(URL, Parameters)
        Wait For (j) JobDone(j As HttpJob)
        If j.Success Then
            ResultURL = j.GetString
        End If
    Catch
        Log(LastException.Message)
    End Try
    j.Release
    Return ResultURL
End Sub
 
Last edited:

TILogistic

Expert
Licensed User
Longtime User
METODO POST:
B4X:
Public Sub TestURL2
    Dim URL As String = "https://xxxxxx.vvvvv.com:1111/ffffff?key=123"
   
    Dim ListParametros As List
    ListParametros.Initialize2(Array As String("","CLIENTES_P_WEB","","","","","","","",""))
 
    Dim JSONGenerator As JSONGenerator
    JSONGenerator.Initialize(CreateMap("metodo": "ejecutar_query", "parametros": ListParametros))
    Dim JsonParametros As String = JSONGenerator.ToString

    Wait For (PostURL(URL, JsonParametros)) Complete (DataResult As String)
    Log(DataResult)
       
End Sub

B4X:
Public Sub PostURL(URL As String, Parameters As String) As ResumableSub
    Dim ResultURL As String
    Dim j As HttpJob
    Try
        j.Initialize("", Me)
        j.PostString(URL, Parameters)
        j.GetRequest.SetContentType("application/json")
        Wait For (j) JobDone(j As HttpJob)
        If j.Success Then
            ResultURL = j.GetString
        End If
    Catch
        Log(LastException.Message)
    End Try
    j.Release
    Return ResultURL
End Sub
 
Top