Requesting data from DealerSocket - JAVA

MisterH

New Member
Apr 14, 2017
5
0
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 -

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. :)
 

MisterH

New Member
Apr 14, 2017
5
0
What is the error you're getting?

If you need to do HTTP Basic Auth
No error however there's 3 parameters that the website takes. I will give a shot for the link you posted and let you know what error I'm getting. Thanks Adil.
 

Users who are viewing this thread

Top