private string DoLogin(List <string> result) { var jsData = Path.Combine(_configFolder, "login-data.js"); Dictionary <string, string> values = JsonConvert.DeserializeObject <Dictionary <string, string> >(File.ReadAllText(jsData)); var nameValueCollection = new NameValueCollection(); foreach (var kvp in values) { string value = null; if (kvp.Value != null) { value = kvp.Value; } nameValueCollection.Add(kvp.Key, value); } double secondsSince1970 = (DateTime.UtcNow - new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc)).TotalSeconds; nameValueCollection.Add("oauth_timestamp", secondsSince1970.ToString()); nameValueCollection.Add("oauth_nonce", Guid.NewGuid().ToString()); // "XXw271C51BRTLPNaYyWXh3Y9fWU3OXX63OP1BejmCAkAzA" string signature = BltiBuilder.Calculate(nameValueCollection, host: new Uri(_loginUrl).Host, sharedSecret: _sharedSecret); nameValueCollection.Add("oauth_signature", signature); var pairs = new List <string>(); foreach (string key in nameValueCollection) { string value = nameValueCollection[key]; pairs.Add(string.Format("{0}={1}", key, Uri.EscapeDataString(value))); } var data = Encoding.ASCII.GetBytes(string.Join("&", pairs)); HttpWebRequest request = (HttpWebRequest)WebRequest.Create(_loginUrl); request.AllowAutoRedirect = false; request.Method = "POST"; request.ContentType = "application/x-www-form-urlencoded"; using (var stream = request.GetRequestStream()) { stream.Write(data, 0, data.Length); } using (var response = (HttpWebResponse)request.GetResponse()) { return(new StreamReader(response.GetResponseStream()).ReadToEnd()); } }
private string DoLogin(List <string> result) { var jsData = Path.Combine(_configFolder, "login-data.js"); Dictionary <string, string> values = JsonConvert.DeserializeObject <Dictionary <string, string> >(File.ReadAllText(jsData)); var nameValueCollection = new NameValueCollection(); foreach (var kvp in values) { string value = null; if (kvp.Value != null) { value = kvp.Value; } nameValueCollection.Add(kvp.Key, value); } double secondsSince1970 = (DateTime.UtcNow - new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc)).TotalSeconds; nameValueCollection.Add("oauth_timestamp", secondsSince1970.ToString()); //1448451144 //nameValueCollection.Add("oauth_timestamp", "1448451144"); nameValueCollection.Add("oauth_nonce", Guid.NewGuid().ToString()); // "XXw271C51BRTLPNaYyWXh3Y9fWU3OXX63OP1BejmCAkAzA" string signature = BltiBuilder.Calculate(nameValueCollection); nameValueCollection.Add("oauth_signature", signature); var pairs = new List <string>(); foreach (string key in nameValueCollection) { string value = nameValueCollection[key]; pairs.Add(string.Format("{0}={1}", key, Uri.EscapeDataString(value))); } string data = string.Join("&", pairs).Replace("%", "\"%\""); // http://stackoverflow.com/questions/18215389/how-do-i-measure-request-and-response-times-at-once-using-curl // string arguments = string.Format("--config {0} -w %{{time_connect}}:%{{time_starttransfer}}:%{{time_total}} -s --data \"{1}\"", string arguments = string.Format("--data \"{1}\" --config {0} -s", Path.Combine(_configFolder, "login.cfg"), data); return(RunExternalExe(_curlExeFullPath, arguments)); }