AppHarbor.Client.AppHarborClient.GetAccessToken C# (CSharp) Method

GetAccessToken() public method

public GetAccessToken ( string Code ) : string
Code string
return string
        public string GetAccessToken(string Code)
        {
            WebRequest req = WebRequest.Create("https://appharbor.com/tokens");
            req.ContentType = "application/x-www-form-urlencoded";
            req.Method = "POST";

            string parameters = string.Format("client_id={0}&client_secret={1}&code={2}", clientId, secret, HttpUtility.UrlEncode(Code));
            byte[] bytes = System.Text.Encoding.ASCII.GetBytes(parameters);
            req.ContentLength = bytes.Length;
            System.IO.Stream os = req.GetRequestStream();
            os.Write(bytes, 0, bytes.Length); //Push it out there
            os.Close();
            System.Net.WebResponse resp = req.GetResponse();
            if (resp == null) return null;
            System.IO.StreamReader sr = new System.IO.StreamReader(resp.GetResponseStream());
            var respStr = sr.ReadToEnd().Trim();
            var nvc = HttpUtility.ParseQueryString(respStr);

            return nvc["access_token"];
        }