B4J Question Header correction

onair

Member
Licensed User
Longtime User
how to translate from java code to B4J this:
B4X:
httpGet.addHeader("Authorization", "Basic "+Base64.encodeToString("rat#1:rat".getBytes(),Base64.NO_WRAP));

regards
 

DonManfred

Expert
Licensed User
Longtime User
something like

B4X:
   Dim Job As HttpJob
   Job.Initialize("fcm", Me)
   Job.Download("https://www.google.com")
   'Job.GetRequest.SetContentType("application/json;charset=UTF-8")
   Job.GetRequest.SetHeader("Authorization", "Basic "&Base64.encodeToString("rat#1:rat".getBytes(),Base64.NO_WRAP))

Note that you need to set the header AFTER job.download/poststring...

Edit: The base64 you can do with stringutils and Byteconverter.
B4X:
su.EncodeBase64(bc.StringToBytes(USERNAME&":"&PASSWORD,"ASCII"))
 
Upvote 0

onair

Member
Licensed User
Longtime User
I apologize that the google translation makes no sense, but the goal is that I can make settings for the header from PHP scripts in B4J. Specifically this part of PHP code:
B4X:
curl_setopt($ch, CURLOPT_HEADER, 1);
        curl_setopt($ch, CURLOPT_REFERER, $this->baseurl.'/login');
        curl_setopt($ch, CURLOPT_URL, $this->baseurl.'/api/login');
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
If you want to use PHP then use it.

If you want to send requests from b4j then you should use okhttputils.
Yes, you can set referer and url headers.
You just need to know the Headername (whats behind the CURLOPT_REFERER or CURLOPT_URL) to set it.

Maybe you should learn english and do not rely on faulty google translations.
 
Upvote 0
Top