B4J Question jOkHttpUtils2 GetString response with PHP

ThRuST

Well-Known Member
Licensed User
Longtime 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
Longtime 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).
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
I would just do PHP Script 1 do all the work (including calling the second one)
 
Upvote 0

ThRuST

Well-Known Member
Licensed User
Longtime 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.
 
Upvote 0

OliverA

Expert
Licensed User
Longtime 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 )?
 
Upvote 0

ThRuST

Well-Known Member
Licensed User
Longtime 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.
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime 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:
Upvote 0
Top