Menu
Forums
All threads
Latest threads
New posts
Trending threads
New posts
Search forums
Trending
What's new
New posts
New profile posts
Latest activity
Members
Current visitors
New profile posts
Search profile posts
Upgrades
Log in
Register
What's new
Search
Search
Search titles only
By:
All threads
Latest threads
New posts
Trending threads
New posts
Search forums
Menu
Log in
Register
Navigation
Install the app
Install
More options
Contact us
Close Menu
Forums
Software Development
Programming
Programming Q&A
Requesting data from DealerSocket - JAVA
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Reply to thread
Message
<blockquote data-quote="MisterH" data-source="post: 440276" data-attributes="member: 75278"><p>Hello all,</p><p></p><p>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 -</p><p></p><p>[CODE]https class Program</p><p>{</p><p>static void Main(string[] args)</p><p>{</p><p>{</p><p>BaseAddress = new Uri(url) };</p><p>client.DefaultRequestHeaders.Accept.Add((new MediaTypeWithQualityHeaderValue("application/json")));</p><p>var response = client.GetAsync("?username=user@dealersocket.com&password=test&InstitutionID=####").Result; if (response.IsSuccessStatusCode)</p><p>{</p><p>var myResult = response.Content.ReadAsAsync<AuthenticateResult>();</p><p>if (myResult.Result.Status == 0) {</p><p>Console.WriteLine("My Token is: " + myResult.Result.Token); Console.ReadLine(); }</p><p>else</p><p>{</p><p>Console.WriteLine("Error: " + myResult.Result.Message); Console.ReadLine(); }</p><p>}</p><p>}</p><p>public class AuthenticateResult</p><p>{</p><p>public int Status { get; set; } public string Token { get; set; } public string Message { get; set; } }</p><p>}</p><p> const string url = " https://idms.dealersocket.com/api/authenticate/GetUserAuthorizationToken";</p><p>var client = new HttpClient</p><p> [/CODE]</p><p></p><p>I know how to create a basic authenticator in Java which would further help me request a Token with your help. </p><p>Here's what I've done so far. </p><p></p><p>[CODE]import jdk.incubator.http.HttpClient;</p><p></p><p>import java.io.BufferedReader;</p><p>import java.io.InputStream;</p><p>import java.io.InputStreamReader;</p><p>import java.net.HttpURLConnection;</p><p>import java.net.URL;</p><p>import java.util.Base64;</p><p></p><p>public class Token {</p><p></p><p> private static final String ENCODING = "UTF-8";</p><p></p><p> public static void main(String[] args) throws Exception {</p><p></p><p> try {</p><p> URL url = new URL("https://idms.dealersocket.com/api/authenticate/GetUserAuthorizationToken");</p><p> String encoding = Base64.getEncoder().encodeToString(("Username@HoustonDirectAuto.com:Password").getBytes("UTF-8"));</p><p></p><p> HttpURLConnection connection = (HttpURLConnection) url.openConnection();</p><p> connection.setRequestMethod("POST");</p><p> connection.setDoOutput(true);</p><p> connection.setRequestProperty("Authorize", "Basic " + encoding);</p><p> InputStream content = (InputStream)connection.getInputStream();</p><p> BufferedReader in = new BufferedReader(new InputStreamReader(content));</p><p> String line;</p><p> while((line = in.readLine()) != null) {</p><p> System.out.println(line);</p><p> }</p><p> } catch (Exception e) {</p><p> e.printStackTrace();</p><p> }</p><p> }</p><p>}</p><p>[/CODE]</p><p></p><p>Appreciating any help regarding this. <img src="/styles/default/xenforo/smilies/emojione/smile.png" class="smilie" loading="lazy" alt=":)" title="Smile :)" data-shortname=":)" /></p></blockquote><p></p>
[QUOTE="MisterH, post: 440276, member: 75278"] 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("?username=user@dealersocket.com&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 [/CODE] 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(("Username@HoustonDirectAuto.com: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(); } } } [/CODE] Appreciating any help regarding this. :) [/QUOTE]
Insert quotes…
Verification
Post reply
Forums
Software Development
Programming
Programming Q&A
Requesting data from DealerSocket - JAVA
Top