Android Question Hello, I am sending a value to a php file via the $_POST function and I am receiving an error

AlfaizDev

Well-Known Member
Licensed User
Longtime User
Hello, I am sending a value to a php file via the $_POST function and I am receiving an error
When I use the $_Get function it works fine
But the problem is when changing to the $_POST function
Although he was working a while ago
This is a test page for that
Thank you all
I tried a lot of solutions and it didn't work for me

b4a:
Private Sub SwiftButton1_Click
    
    Dim resJob As String
    Dim server As String="https://www.alfaiz678.com/test.php"
    
    Dim JobX As HttpJob
    JobX.Initialize("JobX", Me)
    
    JobX.PostString(server, _
     "action=B4X Simple, powerful and moderndevelopment tools." )
'    
'    JobX.Download2(server, _
'     Array As String ("action","B4X Simple, powerful and moderndevelopment tools." ))

    JobX.GetRequest.Timeout=15000
    
    Wait For (JobX) JobDone(j As HttpJob)
    If j.Success Then
        
        resJob = J.GetString
        Log("Response from server: " & resJob)        
        'xui.MsgboxAsync(resJob,"")
    End If
    j.Release

End Sub

php:
<?php

//if(isset($_GET['action']))
if(isset($_POST['action']))

{
 //   $action = $_GET['action'];
    $action = $_POST['action'];
    echo $action;
}

else

{
    echo "Index is empty";
}



?>


The result with the $_GET function
B4X:
Response from server: B4X Simple, powerful and moderndevelopment tools.

Result with $_POST function
b4a:
Response from server: Index is empty
 
Solution
B4X:
Private Sub Button1_Click
    Dim resJob As String
    Dim server As String="https://www.alfaiz678.com/test.php"
    
    Dim JobX As HttpJob
    JobX.Initialize("JobX", Me)

    Dim m As Map = CreateMap("action":"B4X Simple, powerful and moderndevelopment tools.")
    
    JobX.PostMultipart(server, m,Null)
    JobX.GetRequest.Timeout=15000
    Wait For (JobX) JobDone(j As HttpJob)
    If j.Success Then
      resJob = J.GetString
        Log("Response from server: " & resJob)
    End If
    j.Release
End Sub

Logger connected to: samsung SM-G973F
--------- beginning of main
*** Service (starter) Create ***
** Service (starter) Start **
** Activity (main) Create (first time) **
*** mainpage: B4XPage_Created
*** mainpage...

aeric

Expert
Licensed User
Longtime User
I tried your code, it actually works at my side (if i remove the isset).

use:
PHP:
if(!empty($_POST['action']))
 
Upvote 0

AlfaizDev

Well-Known Member
Licensed User
Longtime User
I tried your code, it actually works at my side (if i remove the isset).

use:
PHP:
if(!empty($_POST['action']))
I also tried that before to no avail
The same result appears

Index is empty
 
Upvote 0

AlfaizDev

Well-Known Member
Licensed User
Longtime User
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
B4X:
Private Sub Button1_Click
    Dim resJob As String
    Dim server As String="https://www.alfaiz678.com/test.php"
    
    Dim JobX As HttpJob
    JobX.Initialize("JobX", Me)

    Dim m As Map = CreateMap("action":"B4X Simple, powerful and moderndevelopment tools.")
    
    JobX.PostMultipart(server, m,Null)
    JobX.GetRequest.Timeout=15000
    Wait For (JobX) JobDone(j As HttpJob)
    If j.Success Then
      resJob = J.GetString
        Log("Response from server: " & resJob)
    End If
    j.Release
End Sub

Logger connected to: samsung SM-G973F
--------- beginning of main
*** Service (starter) Create ***
** Service (starter) Start **
** Activity (main) Create (first time) **
*** mainpage: B4XPage_Created
*** mainpage: B4XPage_Appear
** Activity (main) Resume **
*** Receiver (httputils2service) Receive (first time) ***
Response from server: B4X Simple, powerful and moderndevelopment tools.
 
Upvote 0
Solution

AlfaizDev

Well-Known Member
Licensed User
Longtime User
You are calling from browser!
NOT B4A
From within b4x it is working now
I just sent you pictures
Because you said you couldn't just believe me
to see

But from inside b4x it works
B4X:
Waiting for debugger to connect...
Program started.
Call B4XPages.GetManager.LogEvents = True to enable logging B4XPages events.
server : https://www.alfaiz678.com/test.php
Response from server: B4X Simple, powerful and moderndevelopment tools.

B4J
 
Upvote 0

aeric

Expert
Licensed User
Longtime User
From within b4x it is working now
I just sent you pictures
Because you said you couldn't just believe me
to see

But from inside b4x it works
B4X:
Waiting for debugger to connect...
Program started.
Call B4XPages.GetManager.LogEvents = True to enable logging B4XPages events.
server : https://www.alfaiz678.com/test.php
Response from server: B4X Simple, powerful and moderndevelopment tools.
You should understand what is GET vs POST, job.Download vs job.PostString
If you use browser to open the URL, it only make GET request, it can't make POST request, if you want to test in PC, you need to use Postman

edit: Unless you use Form tag and submit button
 
Upvote 0

AlfaizDev

Well-Known Member
Licensed User
Longtime User
You should understand what is GET vs POST, job.Download vs job.PostString
If you use browser to open the URL, it only make GET request, it can't make POST request, if you want to test in PC, you need to use Postman

edit: Unless you use Form tag and submit button
Thanks
I did not know this information
 
Upvote 0

AlfaizDev

Well-Known Member
Licensed User
Longtime User
I am not good at using php
I use it only when I need to connect my applications to the server
 
Upvote 0
Top