Android Question need help on poststring.

chaiwatt

Member
Licensed User
Longtime User
Hi Erel!,
I really need help on HttpUtils2, I use poststring method to put input criteria into php code.

Dim Job As HttpJob
Job.Initialize("JobPostName",Me)
Job.PostString ("http://xxxxxx.com/getmysql.php","tbid=mytable" & "&mday=" & itemday & "&mmonth=" & itemmonth & "&myear=" & itemyear )


I can have correct content only first request.

Dim tempstr As String
Log("JobName = " & Job.JobName & ", Success = " & Job.Success)
If Job.Success = True Then
Select Job.JobName
Case "JobPostName"
tempstr = Job.getstring


Let say I have result like this.
======
Name:Mr.AAA Salary:AAA
Name:Mr.BBB Salary:BBB
Name:Mr.CCC Salary:CCC
Name:Mr.DDD Salary:DDD
Name:Mr.EEE Salary:EEE
======

Then I try changing criteria on next request but I still get the same content. Seem HttpUtils does not fetch new data or pending on cookie something, I don't know. Pls advise,thanks.





 
try like this...

B4X:
Expand Collapse Copy
Dim Job As HttpJob
Job.Initialize("JobPostName",Me)
Job.PostString ("http://xxxxxx.com/getmysql.php","tbid=mytable" & "&mday=" & itemday & "&mmonth=" & itemmonth & "&myear=" & itemyear & "&r=" & rnd(1,999999) )
 
Upvote 0
@sorex! I trid but not work, I still have the same result. I try manually request via php and work fine but not work via b4a httputilss poststring method. I hope I can have luck form Erel.
 
Upvote 0
I run on real android device and not work, But work well on avd simulator. I just wonder why it not the same?.
 
Upvote 0
Did you reuse the job or did you DIM a new one every time. The last said should be the one you are doing...
 
Upvote 0
oh it's post, my bad :)

try this then...

B4X:
Expand Collapse Copy
Dim Job As HttpJob
Job.Initialize("JobPostName",Me)
Job.PostString ("http://xxxxxx.com/getmysql.php?r=" & rnd(1,999999),"tbid=mytable" & "&mday=" & itemday & "&mmonth=" & itemmonth & "&myear=" & itemyear)
 
Upvote 0
it might drop the parameter since it's posting tho.

last thing you could try is add an header in the php file so that the page expires immediatly.

B4X:
Expand Collapse Copy
header("Cache-Control: no-store, no-cache, must-revalidate");
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache");
 
Upvote 0
Hi Manfred, After declare job object then I use the poststring method, get content and release at final. For next req, I do the same thing, then job is new created every time. I notice that the second req is too fast seem no fetch and so no new data loaded. And I just doubt that why it work on simulator but not work on real device (via b4a bridge).
 
Upvote 0
Hi Manfred, After declare job object then I use the poststring method, get content and release at final. For next req, I do the same thing, then job is new created every time. I notice that the second req is too fast seem no fetch and so no new data loaded. And I just doubt that why it work on simulator but not work on real device (via b4a bridge).

What do you mean with the same thing? Does your "same thing" include the DIM???
B4X:
Expand Collapse Copy
Dim Job As HttpJob

Maybe you should upload your project (export as zip) and we can have a look at it
 
Upvote 0
I'll post my source tomorrow. My county time now is almost 1am. Feel sleepi now :confused: appreciated & thanks Sorex and Manfred for helping.
 
Upvote 0
If you have control over the php-file then you could insert logging-functions into it so see all given parameters
PHP:
Expand Collapse Copy
$file_handle = fopen('./b4a.log', 'a+');
fwrite($file_handle, "======================================"."\r\n");
foreach($_REQUEST as $name => $value){
    fwrite($file_handle, date("d.m.Y H:i:s", time()).": ".$name."=".$value." "."\r\n");
}
fwrite($file_handle, "======================================"."\r\n");
fclose($file_handle);
 
Upvote 0
chaiwatt: since the parameters are all small you could go for get instead of post with the randomize in the url as parameter.
(don't forget to search/replace the $_POST with $_GET in the php file)
 
Upvote 0
true, I requested the randomizer trick into the fetch routines before but I'm not sure if Erel will add it.
 
Upvote 0
Top