Italian httpClient mi fa impazzire dagli errori.

ivanomonti

Expert
Licensed User
Longtime User
ciao a tutti, ho un pezzetto di codice che mi preleva i dati json da server e mysql, il metodo utilizzato il classico pagina php che riceve un codice e estrappola dati.

1) la query se la emulo su safari, IE, firefox e altri va da dio
2) se invio la query su codice B4A in modalità debug va a random
3) se compilo APK non va più

ho buttato il progetto e riscritto tutto da capo pensando che il problema fosse legato a file corrotti, stesso problema. non ne esco più.

Chi mi da una mano.


B4X:
Sub LoadListClick
   
    hc.Initialize("hc")
   
    Dim s,ss As String
    s = Encode64("Select * from tabella")
    ss = host&s
   
    Dim req As HttpRequest
    req.Timeout = 10000
    req.InitializeGet(ss)
   
    Try
        hc.Execute(req,1)
    Catch
        ToastMessageShow("Error request...line internet not present", True)
    End Try
   
End Sub


B4X:
Sub hc_ResponseError (Response As HttpResponse, Reason As String, StatusCode As Int, TaskId As Int)
    Response.Release
End Sub

Sub hc_ResponseSuccess (Response As HttpResponse, TaskId As Int)

    If Response <> Null Then
        ListView1.Clear
    Else
        Return
    End If
   
    Try
   
    Dim s As String
    s = Response.GetString("UTF8")
   
    Log(s)
   
    Dim JSON As JSONParser
    Dim root As List
    JSON.Initialize(s)
    root = JSON.NextArray

    For Each colroot As Map In root
          Dim a01 As String = colroot.Get("a01")
          Dim a02 As String = colroot.Get("a02")
          Dim a03 As String = colroot.Get("a03")
          Dim a04 As String = colroot.Get("a04")
          Dim a05 As String = colroot.Get("a05")
          Dim a06 As String = colroot.Get("a06")
          Dim a07 As String = colroot.Get("a07")
          Dim a08 As String = colroot.Get("a08")
          Dim a09 As String = colroot.Get("a09")
          Dim r1 As String = colroot.Get("r1")
        ListView1.AddTwoLinesAndBitmap(a01,a02,LoadBitmap(File.DirAssets,a03))
    Next
    Response.Release
    Catch
        ToastMessageShow("Error server ",True)
        Response.Release
    End Try
End Sub
 

ivanomonti

Expert
Licensed User
Longtime User
Nessun errore ma nessun record... come se quando compili httpclient va in palla, se faccio stessa operazione con debug e debug veloce arrivano i record se compilo non arrivano i record... mistero
 

ivanomonti

Expert
Licensed User
Longtime User
provo a fare un thread separato o classe separata poi ti aggiorno, perché perdere 2 gg per una cagata del genere e pazzesco
 

ivanomonti

Expert
Licensed User
Longtime User
Mi sto incazzando come un bufalo.... sempre stesso problema

1) se compilo debug = ok
2) se compilo debug Rapid = ok
3) se compilo apk nativa = null no record
4) se compilo apk nativa ofuscata = null no record

Non riesco a trovare errore cazzarola.

Classe fuori activity

B4X:
'Class module
Sub Class_Globals
    Dim hc As HttpClient
    Dim a01 As List
    Dim a02 As List
    Dim a03 As List
    Dim a04 As List
    Dim a05 As List
    Dim a06 As List
    Dim a07 As List
    Dim a08 As List
    Dim a09 As List
    Dim r1 As List
End Sub

'Initializes the object. You can add parameters to this method if needed.
Public Sub Initialize
    hc.Initialize("hc")
    a01.Initialize
    a02.Initialize
    a03.Initialize
    a04.Initialize
    a05.Initialize
    a06.Initialize
    a07.Initialize
    a08.Initialize
    a09.Initialize
    r1.Initialize
End Sub


Public Sub LoadListClick(query As String)
 
    Dim s,ss As String
    s = Encode64(query)
    ss = host
 
    Dim req As HttpRequest
    req.InitializePost2(ss,("query="&s).GetBytes("UTF8"))
 
    Try
        hc.Execute(req, 1)
        ProgressDialogShow("Processing Data")
    Catch
        ToastMessageShow("Error request...line internet not present", True)
    End Try
 
End Sub

Sub hc_ResponseError (Response As HttpResponse, Reason As String, StatusCode As Int, TaskId As Int)
    Response.Release
End Sub

Sub hc_ResponseSuccess (Response As HttpResponse, TaskId As Int)

    If Response <> Null Then
        a01.Initialize
        a02.Initialize
        a03.Initialize
        a04.Initialize
        a05.Initialize
        a06.Initialize
        a07.Initialize
        a08.Initialize
        a09.Initialize
        r1.Initialize
    Else
        ProgressDialogHide
        Return
    End If
 
    Try
 
    Dim s As String
    s = Response.GetString("UTF8")
 
    If s = "Error" OR s = "No records found" OR s = "Query invalid" Then
        ProgressDialogHide
        Return
    End If
 
    Log(s)
 
    Dim JSON As JSONParser
    Dim root As List
    JSON.Initialize(s)
    root = JSON.NextArray

    For Each colroot As Map In root
        a01.Add(colroot.Get("a01"))
        a02.Add(colroot.Get("a02"))
        a03.Add(colroot.Get("a03"))
        a04.Add(colroot.Get("a04"))
        a05.Add(colroot.Get("a05"))
        a06.Add(colroot.Get("a06"))
        a07.Add(colroot.Get("a07"))
        a08.Add(colroot.Get("a08"))
        a09.Add(colroot.Get("a09"))
        r1.Add(colroot.Get("r1"))
    Next
    Response.Release
    ProgressDialogHide
    Catch
        Response.Release
        ProgressDialogHide
    End Try
End Sub

Public Sub host() As String
    Dim ServerUrl As String
    ServerUrl = "http://XXXXXXXXXXX.eu/XXXX/script.php"
    Return ServerUrl
End Sub

Sub Encode64(s As String) As String
    Dim code As Base64
    Return code.EncodeStoS(s,"UTF8")
End Sub

Sub Decode64(s As String) As String
    Dim code As Base64
    Return code.DecodeStoS(s,"UTF8")
End Sub

Chiamata da activity alla sua creazione


B4X:
Sub Activity_Create(FirstTime AsBoolean)
     chc.Initialize
    chc.LoadListClick("Select * from seigogo")
End sub

popolo la Listview

B4X:
Sub Reload_Click
For i = 0Tochc.a01.Size-1
Log(chc.a01.Get(i) & "-" & chc.a02.Get(i))
ListView1.AddTwoLinesAndBitmap(chc.a01.Get(i),chc.a02.Get(i),Null)
Next
End Sub

Pagina Php sul server

PHP:
<?

$databasehost = "localhost";
$databasename = "xxxxxxxxxxx";
$databaseusername ="xxxxxxxxxxxxx";
$databasepassword = "xxxxxxxxxx";

$objConnect = mysql_connect($databasehost,$databaseusername,$databasepassword);
$objDB = mysql_select_db($databasename );

$objQuery = mysql_query(base64_decode($_POST['query']));

$intNumRows = mysql_num_rows($objQuery);

if ( $intNumRows == null || $intNumRows = 0 )
{
    if ( substr(strtoupper($_POST['query']), 0, 5) === "SELECT" ){print "No records found";}
    mysql_close($objConnect);
    return;
 
}

$rows = array();
while($r = mysql_fetch_assoc($objQuery ))
{
    $rows[] = $r;
}

print json_encode($rows);
mysql_close($objConnect);

?>

Posso arrabbiarmi, poi non e che il modulo admod influisce :-(

B4X:
Sub Activity_Create(FirstTime AsBoolean)
Activity.LoadLayout("Main")
Activity.AddMenuItem2("Add","Add",Null)
Activity.AddMenuItem2("Reload","Reload",Null)
Activity.AddMenuItem2("List Clear","ListClear",Null)
Activity.AddMenuItem2("Quit","Quit",Null)

AdView1.Initialize("Ad", "ca-app-pub-2294438034619787/4549328314")
Activity.AddView(AdView1, 0dip,0dip, Activity.Width, 50dip)

AdView1.LoadAd

chc.Initialize
chc.LoadListClick("Select * from seigogo")

End Sub
 
Last edited:

moster67

Expert
Licensed User
Longtime User
Puoi provare con httputils2 (è disponibile sia in codice oppure come libreria). Eril lo consiglia. Mi sembra di aver capito dalla tua disperazione che oramai non hai niente di perdere oltre tempo.
 

ivanomonti

Expert
Licensed User
Longtime User
già ma che palle uffa, ora provo con httputils2 ma mi sembra assurdo, ho Erel lo dichiara obsoleto o drepecato ho trova una soluzione al caso.
 

ivanomonti

Expert
Licensed User
Longtime User
infatti era lo stesso problema con mysql library... stando con la versione 4 tutto va bene con la 14 no. cmq da valutare bene la cosa.

Grazie per la segnalazione.
 
Top