B4J Question jOkHttpUtils2 GetString response with PHP

ThRuST

Well-Known Member
Licensed User
When sending a PostString request using jOkHTTPUtils2 a PHP Echo response can be shown in the PHP script on the server. The problem is that I have to send a separate request just to get a response value from Echo, and then send another Request to another PHP script to do whatever to be done, depending if the first script returns for example True or False. Is there a way to get the response from Echo in GetString and handle the second action within the same process?

I can illustrate this in a sequence:

1. send a job to the server.
2. the first PHP script returns a response using Echo.
3. if GetString receives True then we calls 4
4. Send a new job to call the second PHP script

Perhaps this can be dealt with differently?
 

OliverA

Expert
Licensed User
When sending a PostString request using jOkHTTPUtils2 a PHP Echo response can be shown in the PHP script on the server. The problem is that I have to send a separate request just to get a response value from Echo
You do? Odd, have you tried it on the B4J side? Where is your code. Even with POSTing, the GetString function should still contain the response given by the server, unless the response code is not 200 (j.success = False).
 

ThRuST

Well-Known Member
Licensed User
@OliverA yes I tried this in B4J. The challenge in this is to send back a second Echo to GetString from the first job depending on what the PHP script should do.

@DonManfred Nice implementation. If I can just figure out a way in which sequence Echo can return a response to the application. Possibly multiple Echo responses can be handled from the first job.
 

OliverA

Expert
Licensed User
The challenge in this is to send back a second Echo to GetString from the first job depending on what the PHP script should do
Are you in control of the PHP scripts? Why would you send two "Echo"'s? You process the info on the server, and then you send back one message. Plus, if the same server has to just act on he outcome of the first POST, why not just act on the first post on the server side (as per @DonManfred )?
 

ThRuST

Well-Known Member
Licensed User
I guess I should find some examples how to write improved PHP scripts. The process of what worked for me was something I wanted to share to have a chance to learn other (better) methods. I should plan out how the PHP scripts should work so I guess the answer is that I need to level up my PHP skills which turned a bit rusty.

Any further advice how to have GetString receive a second Echo string is highly appreciated since it can open up for enhancements.
 

ThRuST

Well-Known Member
Licensed User
@DonManfred Are you familiar with any json posts you might link to for the second alternative related to this would be super.
 

DonManfred

Expert
Licensed User
PHP:
  $appversion = array();
  $appversion["Version"] = APPVERSION;
  $appversion["Name"] = "KvTools";
  $appversion["DeviceID"] = $DeviceID;
  $appversion["Token"] = $token;
  echo json_encode($appversion);
PHP:
    $sql  = "SELECT * FROM `table` t ";
    $logged = $db->rawQuery($sql, null); # mySQLi-Class
    echo json_encode($logged);
 
Last edited:
Top