Hello all,
I am asking for a favor from all of you with this Java code, What I'm trying to do here is basically converting this code to Java -
I know how to create a basic authenticator in Java which would further help me request a Token with your help.
Here's what I've done so far.
Appreciating any help regarding this.
I am asking for a favor from all of you with this Java code, What I'm trying to do here is basically converting this code to Java -
Code:
https class Program
{
static void Main(string[] args)
{
{
BaseAddress = new Uri(url) };
client.DefaultRequestHeaders.Accept.Add((new MediaTypeWithQualityHeaderValue("application/json")));
var response = client.GetAsync("[email protected]&password=test&InstitutionID=####").Result; if (response.IsSuccessStatusCode)
{
var myResult = response.Content.ReadAsAsync<AuthenticateResult>();
if (myResult.Result.Status == 0) {
Console.WriteLine("My Token is: " + myResult.Result.Token); Console.ReadLine(); }
else
{
Console.WriteLine("Error: " + myResult.Result.Message); Console.ReadLine(); }
}
}
public class AuthenticateResult
{
public int Status { get; set; } public string Token { get; set; } public string Message { get; set; } }
}
const string url = " https://idms.dealersocket.com/api/authenticate/GetUserAuthorizationToken";
var client = new HttpClient
I know how to create a basic authenticator in Java which would further help me request a Token with your help.
Here's what I've done so far.
Code:
import jdk.incubator.http.HttpClient;
import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.Base64;
public class Token {
private static final String ENCODING = "UTF-8";
public static void main(String[] args) throws Exception {
try {
URL url = new URL("https://idms.dealersocket.com/api/authenticate/GetUserAuthorizationToken");
String encoding = Base64.getEncoder().encodeToString(("[email protected]:Password").getBytes("UTF-8"));
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setRequestMethod("POST");
connection.setDoOutput(true);
connection.setRequestProperty("Authorize", "Basic " + encoding);
InputStream content = (InputStream)connection.getInputStream();
BufferedReader in = new BufferedReader(new InputStreamReader(content));
String line;
while((line = in.readLine()) != null) {
System.out.println(line);
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
Appreciating any help regarding this.