B4R Question passing value to php backend

sorex

Expert
Licensed User
Longtime User
Hello,

What's an good method to pass a value to a php based backend?

I have the .download & .post options via the HttpJob class but ...

I can't seem to concat a value to the url string in B4R for the download option

I don't know what this payload array is for the post option.

Should I pass the value by using additional headers or are there other methods that I'm not aware of yet?
 

sorex

Expert
Licensed User
Longtime User
from the moment that I add the HttpJob class to my project my project doesn't compile anymore.

I have rCore, rESP8266Wifi, rMFRC522 & rRandomAccessFile libs selected.

B4X:
Compiling & deploying Ino project (WEMOS LOLIN32 - COM6)    Error
Loading configuration...
Initializing packages...
DEBUG StatusLogger Using ShutdownCallbackRegistry class org.apache.logging.log4j.core.util.DefaultShutdownCallbackRegistry
DEBUG StatusLogger Not in a ServletContext environment, thus not loading WebLookup plugin.
DEBUG StatusLogger AsyncLogger.ThreadNameStrategy=UNCACHED (user specified null, default is UNCACHED)
TRACE StatusLogger Using default SystemClock for timestamps.
DEBUG StatusLogger org.apache.logging.log4j.core.util.SystemClock does not support precise timestamps.
DEBUG StatusLogger Not in a ServletContext environment, thus not loading WebLookup plugin.
DEBUG StatusLogger Took 0.123039 seconds to load 209 plugins from sun.misc.Launcher$AppClassLoader@af3868
DEBUG StatusLogger PluginManager 'Converter' found 44 plugins
DEBUG StatusLogger Starting OutputStreamManager SYSTEM_OUT.false.false-1
DEBUG StatusLogger Starting LoggerContext[name=af3868, org.apache.logging.log4j.core.LoggerContext@804139]...
DEBUG StatusLogger Reconfiguration started for context[name=af3868] at URI null (org.apache.logging.log4j.core.LoggerContext@804139) with optional ClassLoader: null
DEBUG StatusLogger Not in a ServletContext environment, thus not loading WebLookup plugin.
DEBUG StatusLogger PluginManager 'ConfigurationFactory' found 4 plugins
DEBUG StatusLogger Not in a ServletContext environment, thus not loading WebLookup plugin.
DEBUG StatusLogger Not in a ServletContext environment, thus not loading WebLookup plugin.
DEBUG StatusLogger Missing dependencies for Yaml support, ConfigurationFactory org.apache.logging.log4j.core.config.yaml.YamlConfigurationFactory is inactive
DEBUG StatusLogger Not in a ServletContext environment, thus not loading WebLookup plugin.
DEBUG StatusLogger Not in a ServletContext environment, thus not loading WebLookup plugin.
DEBUG StatusLogger Using configurationFactory org.apache.logging.log4j.core.config.ConfigurationFactory$Factory@167f57d
TRACE StatusLogger Trying to find [log4j2-testaf3868.properties] using context class loader sun.misc.Launcher$AppClassLoader@af3868.
 
Upvote 0

sorex

Expert
Licensed User
Longtime User
I don't know what went wrong earlier but now it compiles and runs fine.

The only problem I noticed is that the POSTing doesn't work and doesn't send over the values.

Via GET it worked right away.

Here's an example on how to do it especially the concatenating is different to what we're used to and took me a while to figure out.

B4X:
Sub sendTag(Tag As String)
    Dim url As String=JoinStrings(Array As String("http://192.168.0.9/rfid.php?op=writeID&id=",Tag))
    HttpJob.Download(url)   
End Sub
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
The only problem I noticed is that the POSTing doesn't work and doesn't send over the values.
The php-Script must be configured properly to accept poststring.
Usually the best way to work with a PHP-Script is to use POST-Requests (PostMultipart) and get the Post-Values in PHP....
How does the PHP Code look like?
 
Upvote 0

sorex

Expert
Licensed User
Longtime User
like this but with POST instead of GET.

B4X:
$op="";
if (isset($_GET["op"])) {$op=$_GET["op"];}

switch ($op) {
case "":showID();break;
case "writeID":writeID();break;
case "readID":readID();break;
}

using print_r($_POST); (and GET) showed that the collection was just empty.
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
using print_r($_POST); (and GET) showed that the collection was just empty.
I always use $_REQUEST to get values from a multipartpost Request. And i do use PHP a lot in my Apps as a DB-Bridge (man in the middle)
PHP:
    if (isset($_REQUEST['viewall'])){$viewall=intval($_REQUEST['viewall']);} else {$viewall=0;}
    if (isset($_REQUEST['action'])){$action=$_REQUEST['action'];} else {$action="init";}
    if (isset($_REQUEST['zusatzID'])){$zusatzID=intval($_REQUEST['zusatzID']);} else {$zusatzID=0;}

Maybe rokhttputils is always sending GET Requests? Don´t know; never used B4R so far...
 
Upvote 0

sorex

Expert
Licensed User
Longtime User
using

B4X:
echo "----------------".chr(10);
print_r($_POST);
echo "----------------".chr(10);
print_r($_GET);
echo "----------------".chr(10);
print_r($_REQUEST);

results in

----------------
Array
(
)
----------------
Array
(
)
----------------
Array
(
)
 
Upvote 0

sorex

Expert
Licensed User
Longtime User
it's currently working with .download(url+parameters) which is currently fine as I will never get to the size boundary of the get request.

it doesn't work when using .post(url,parameters) as mentioned above.

maybe it needs to be in a specific format but all the examples I found seemed to use a plain string altho it mentiones that it needs to be a byte array.
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…