using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Text;
using System.Web;
using System.Web.Script.Serialization;
namespace InfusionSoftApp.Models
{
public class ClassToken
{
public static void Auth()
{
string RefreshToken = “", DeveloperAppKey= "", DeveloperAppSecret= "********************************”;
string tokenUrl = “https://api.infusionsoft.com/token”;
HttpWebRequest request = HttpWebRequest.Create(tokenUrl) as HttpWebRequest;
request.Method = "POST";
request.KeepAlive = true;
request.ContentType = "application/x-www-form-urlencoded";
//request.ContentLength = 1;
try
{
RefreshToken refmodel = new RefreshToken();
refmodel.grant_type = "refresh_token";
refmodel.refresh_token = "*********************";
string inputJsontag = (new JavaScriptSerializer()).Serialize(refmodel);
string authorizationHeaderText =
Convert.ToBase64String(Encoding.UTF8.GetBytes(DeveloperAppKey + ":" + DeveloperAppSecret));
request.Headers[HttpRequestHeader.Authorization] = "Basic " + authorizationHeaderText;
using (var streamWriter = new StreamWriter(request.GetRequestStream()))
{
streamWriter.Write(refmodel);
}
var httpResponse = (HttpWebResponse)request.GetResponse();
using (var streamReader = new StreamReader(httpResponse.GetResponseStream()))
{
var result = streamReader.ReadToEnd();
}
var jsonSerializer = new JavaScriptSerializer();
}
catch (Exception exception)
{
Console.WriteLine(exception);
}
finally
{
Console.ReadLine();
}
}
}