B4J Question [SOLVED] Converting API Call from Curl/Php to B4X...

Magma

Expert
Licensed User
Longtime User
Hi there... i have an api call at curl/php OAuth2/for Bearer Token that working good... and thought to turn it at b4x... but somewhere loosing it...

my call working at curl/php ok it is here:
B4X:
<?php
   
$credentials = "aaaaaaaaaaaaa:bbbbbbbbbbbbbbb";
$ch = curl_init();
$options = array(
    CURLOPT_URL => 'https://agoodsite.com/connect2/agoodtoken',
    CURLOPT_POST => 1,
    CURLOPT_HEADER => false,
    // Set the auth type as `Basic`
    CURLOPT_HTTPAUTH => CURLAUTH_BASIC,
    // Set login and password for Basic auth
    CURLOPT_USERPWD => $credentials,
    CURLOPT_HTTPHEADER => array(
        'Accept: application/json',
        'Content-Type: application/x-www-form-urlencoded'
    ),
    // To send additional parameters in the POST body
    CURLOPT_POSTFIELDS => "mygrant_type=myclient_credentials"
);

curl_setopt_array($ch, $options);
// This is the response for your request
$result = curl_exec($ch);
// This is the response status code (if you are interested)
$status_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);

echo $result;
echo $status_code;

?>
This return me a success...

My B4X try that not works :(
B4X:
    Private j As  HttpJob
    j.Initialize("myapi",Me)
    j.Username="aaaaaaaaaaaaa"
    j.Password="bbbbbbbbbbbbbbb"
    j.PostString("https://agoodsite.com/connect2/agoodtoken?","mygrant_type=myclient_credentials")
    'j.GetRequest.SetHeader("Authorization", "Basic " & "aaaaaaaaaaaaa:bbbbbbbbbbbbbbb") 'other try
    j.GetRequest.Setheader("Accept", "application/json")
    J.GetRequest.SetContentType("application/x-www-form-urlencoded")
This return me a fail..

....where i am doing wrong... ?
 
Top