final private static String apiBaseURL = "https://auth.smtown.com";
final private static String tokenEndPoint = "oauth/check_token";
final private static String basicAuthorization = "MGYxOWYxNG==";
public static void main(String[] args){
//implementation 'org.apache.httpcomponents:httpclient'
try (CloseableHttpClient client = HttpClients.createDefault()) {
List<NameValuePair> data = new ArrayList<>(Arrays.asList(
new BasicNameValuePair( "token", "6c2260c458b0829d613f58f" )
));
HttpPost post = new HttpPost(String.format("%s/%s", apiBaseURL, tokenEndPoint));
post.setHeader("Authorization", String.format("Basic %s", basicAuthorization));
post.setEntity(new UrlEncodedFormEntity(data, StandardCharsets.UTF_8));
try(CloseableHttpResponse response = client.execute(post)) {
if(response.getStatusLine().getStatusCode() == 200) {
String responseData = EntityUtils.toString(response.getEntity(), StandardCharsets.UTF_8);
System.out.println(responseData);
} else { //for error
String responseData = EntityUtils.toString(response.getEntity(), StandardCharsets.UTF_8);
System.out.println(responseData);
}
}
} catch (IOException e){
throw new RuntimeException();
}
}
private readonly string ApiBaseURL = "https://auth.smtown.com";
private readonly string TokenEndPoint = "oauth/check_token";
private readonly string BasicAuthorization = "MGYxOWYxNG==";
private async void GetAccessToken()
{
var data = new Dictionary<string, string> {
{ "token", "6c2260c458b0829d613f58f" }
};
using System.Net.Http.HttpClient client = new(); System.Net.Http.HttpRequestMessage tokenRequest = new()
{
Method = HttpMethod.Post,
RequestUri = new Uri(string.Format("{0}/{1}", ApiBaseURL, TokenEndPoint)),
Content = new FormUrlEncodedContent(data)
};
tokenRequest.Content.Headers.ContentType = new MediaTypeWithQualityHeaderValue("application/x-www-form-urlencoded") { CharSet = "UTF-8" };
tokenRequest.Headers.TryAddWithoutValidation("Authorization", string.Format("Basic {0}", BasicAuthorizaton));
var response = await client.SendAsync(tokenRequest);
if (response.IsSuccessStatusCode)
{
var responseData = await response.Content.ReadAsStringAsync();
Console.WriteLine(responseData);
} else { //for error
var responseData = await response.Content.ReadAsStringAsync();
Console.WriteLine(responseData);
}
}