/// <summary> /// Send an object of type T1, @item, parsed as json string embedded with the /// authentication token, that is build using @user and @token, /// as an HTTP post request to server at address @url. /// This method parse the reserver response using JSON to object of type T2. /// </summary> /// <typeparam name="T1">Type of the data object to send</typeparam> /// <typeparam name="T2">Type of the return object</typeparam> /// <param name="url">address of the server</param> /// <param name="user">username for authentication data</param> /// <param name="token">token for authentication data</param> /// <param name="item">the data item to send in the reuqest</param> /// <returns>the server response parsed as T2 object in json format</returns> public T2 SendPostRequest <T1, T2>(string url, string user, string nonce, string token, T1 item) where T2 : class { var response = SendPostRequest(url, user, nonce, token, item); string x = SimpleCtyptoLibrary.decrypt(response, GetPK()); return(x == null ? null : FromJson <T2>(x)); }
public override string SendPostRequest <T1>(string url, string user, string privateKey, T1 item) { nonceInt += 1; string nonce = nonceInt.ToString(); string userNonce = user + "_" + nonce; string token = SimpleCtyptoLibrary.CreateToken(userNonce, privateKey); var auth = new { user, token, nonce }; JObject jsonItem = JObject.FromObject(item); jsonItem.Add("auth", JObject.FromObject(auth)); StringContent content = new StringContent(jsonItem.ToString()); using (var client = new HttpClient()) { var result = client.PostAsync(url, content).Result; var responseContent = result?.Content?.ReadAsStringAsync().Result; bool failed = false; string decryptedContent = ""; try { decryptedContent = SimpleCtyptoLibrary.decrypt(responseContent, privateKey); //responseContent = decryptedContent; } catch (Exception e) { myLogger.Error("Failed decryption of market response. Error: " + e.Message); failed = true; } if (!failed) { return(decryptedContent); } else { return(responseContent); } } }