Android Question please enable Javascript in your browser or use a browser with Javascript support in httputils2

AriGharavi

Member
Hi, I have problem to send request with httputils2 library (also tried OkHttpUtils2)

my host php code :

PHP:
<?php

function test() {
    $conn = new mysqli ("localhost","un","pass", "db");
    mysqli_select_db('Romance',$conn);
    mysqli_set_charset('utf8');
    $username=$_POST['username'];
    $password=$_POST['password'];
    if (!$conn)
    {
        echo "Error: Unable to connect to MySQL.";
        echo "Debugging errno: " . mysqli_connect_errno();
        echo "Debugging error: " . mysqli_connect_error();
    }
    else
    {
        $result = "INSERT INTO RomReg(`Username`, `Password`, `Coins`) VALUES '$username','$password',10)";
     
        if(mysqli_query($result)){
         
            echo "Done";
         
        }
        else
        {
            echo "Error";
            echo $username;
            echo $password;
        }
    }
}
echo test();
?>

my b4a application code :

B4X:
#Region  Project Attributes
    #ApplicationLabel: B4A_register
    #VersionCode: 1
    #VersionName:
    'SupportedOrientations possible values: unspecified, landscape or portrait.
    #SupportedOrientations: unspecified
    #CanInstallToExternalStorage: False
#End Region

#Region  Activity Attributes
    #FullScreen: False
    #IncludeTitle: True
#End Region

Sub Process_Globals
End Sub

Sub Globals
    Private Button1 As Button
    Private EditText1 As EditText
    Private EditText2 As EditText
End Sub

Sub Activity_Create(FirstTime As Boolean)
    Activity.LoadLayout("Layout")

End Sub

Sub Button1_Click
    Dim j As HttpJob
    j.Initialize("", Me)
    Dim send As String
    send = "username="&EditText1.Text&"&password="&EditText2.Text
    j.PostString("http://www.ariteam.gigfa.com/TF.php",send)
    Wait For (j) Jobdone(j As HttpJob)
    If j.Success = True Then
        Log(j.GetString)
    Else
//err
        ToastMessageShow("خطا در برقراری اتصال" , False)
    End If
    j.Release
End Sub

Log :

<html><body><script type="text/javascript" src="/aes.js" ></script><script>function toNumbers(d){var e=[];d.replace(/(..)/g,function(d){e.push(parseInt(d,16))});return e}function toHex(){for(var d=[],d=1==arguments.length&&arguments[0].constructor==Array?arguments[0]:arguments,e="",f=0;f<d.length;f++)e+=(16>d[f]?"0":"")+d[f].toString(16);return e.toLowerCase()}var a=toNumbers("f655ba9d09a112d4968c63579db590b4"),b=toNumbers("98344c2eee86c3994890592585b49f80"),c=toNumbers("f66bcd66cb958a3d0bfad4cb33146f2c");document.cookie="__test="+toHex(slowAES.decrypt(c,2,a,b))+"; expires=Thu, 31-Dec-37 23:55:55 GMT; path=/"; location.href="http://www.ariteam.gigfa.com/TF.php?i=1";</script><noscript>This site requires Javascript to work, please enable Javascript in your browser or use a browser with Javascript support</noscript></body></html>
 

AriGharavi

Member
The old HttpUtils2 library is not relevant.

Your host returns a html page with JavaScript. Maybe some (soft) malware / adware.
OkHttpUtils2 will never execute JavaScript. It is not a browser.
So, What's I must be do now?
Is there a library for such a thing?
 
Upvote 0

jkhazraji

Active Member
Licensed User
Longtime User
You directed the php script to connect with the localhost,
PHP:
$conn = new mysqli ("localhost","un","pass", "db");
but you asked your app to connect to a remote site.
B4X:
 j.PostString("http://www.ariteam.gigfa.com/TF.php",send)
Is the php file uploaded to the server and does it reside there??.
 
Upvote 0

mc73

Well-Known Member
Licensed User
Longtime User
Two solutions:
1) Use a webview to get into the registration screen. This way, the cookies' javascript will execute. When moving on to the 'real' page, deal with it using okHttpUtils2 by correctly setting headers got from your webView.
2) (More tedious) Check the javascript code, and set your request's headers to whatever this code does.
 
Upvote 0

AriGharavi

Member
Two solutions:
1) Use a webView to get into the registration screen. This way, the cookies' JavaScript will execute. When moving on to the 'real' page, deal with it using okHttpUtils2 by correctly setting headers got from your webView.
2) (More tedious) Check the JavaScript code, and set your request's headers to whatever this code does.
I am weak in English and I hope I have understood your solution correctly.
1-
My php code only displays one word "Done".
And I need a request to read the word, not a web view.
It works like an API.
So if I use Web View, only the user can see the word "Done" and my program can not read the word.
I hope the B4A team add the ability to get media from a web?

2-
I did not have JavaScript code for adding it to the header ☹
 
Upvote 0
Top