diff --git a/ArchiSteamFarm/ArchiWebHandler.cs b/ArchiSteamFarm/ArchiWebHandler.cs index 672e7e4f2..b94197446 100644 --- a/ArchiSteamFarm/ArchiWebHandler.cs +++ b/ArchiSteamFarm/ArchiWebHandler.cs @@ -345,12 +345,24 @@ namespace ArchiSteamFarm { return false; } - StringBuilder request = new StringBuilder(SteamCommunityURL + "/mobileconf/multiajaxop?op=" + (accept ? "allow" : "cancel") + "&p=" + deviceID + "&a=" + SteamID + "&k=" + WebUtility.UrlEncode(confirmationHash) + "&t=" + time + "&m=android&tag=conf"); + string request = SteamCommunityURL + "/mobileconf/multiajaxop"; + + List> data = new List>(7 + confirmations.Count * 2) { + new KeyValuePair("op", accept ? "allow" : "cancel"), + new KeyValuePair("p", deviceID), + new KeyValuePair("a", SteamID.ToString()), + new KeyValuePair("k", confirmationHash), + new KeyValuePair("t", time.ToString()), + new KeyValuePair("m", "android"), + new KeyValuePair("tag", "conf") + }; + foreach (MobileAuthenticator.Confirmation confirmation in confirmations) { - request.Append("&cid[]=" + confirmation.ID + "&ck[]=" + confirmation.Key); + data.Add(new KeyValuePair("cid[]", confirmation.ID.ToString())); + data.Add(new KeyValuePair("ck[]", confirmation.Key.ToString())); } - string json = await WebBrowser.UrlGetToContentRetry(request.ToString()).ConfigureAwait(false); + string json = await WebBrowser.UrlPostToContentRetry(request, data).ConfigureAwait(false); if (string.IsNullOrEmpty(json)) { return false; } diff --git a/ArchiSteamFarm/MobileAuthenticator.cs b/ArchiSteamFarm/MobileAuthenticator.cs index 6107ddfff..c9a723b20 100644 --- a/ArchiSteamFarm/MobileAuthenticator.cs +++ b/ArchiSteamFarm/MobileAuthenticator.cs @@ -25,7 +25,6 @@ using System; using System.Collections.Generic; using System.Diagnostics.CodeAnalysis; -using System.Linq; using System.Security.Cryptography; using System.Text; using System.Threading; diff --git a/ArchiSteamFarm/WebBrowser.cs b/ArchiSteamFarm/WebBrowser.cs index 4bb5d814b..9cdd527b6 100644 --- a/ArchiSteamFarm/WebBrowser.cs +++ b/ArchiSteamFarm/WebBrowser.cs @@ -218,7 +218,7 @@ namespace ArchiSteamFarm { return null; } - internal async Task UrlPostRetry(string request, Dictionary data = null, string referer = null) { + internal async Task UrlPostRetry(string request, ICollection> data = null, string referer = null) { if (string.IsNullOrEmpty(request)) { Logging.LogNullError(nameof(request), Identifier); return false; @@ -237,6 +237,25 @@ namespace ArchiSteamFarm { return false; } + internal async Task UrlPostToContentRetry(string request, ICollection> data = null, string referer = null) { + if (string.IsNullOrEmpty(request)) { + Logging.LogNullError(nameof(request), Identifier); + return null; + } + + string result = null; + for (byte i = 0; (i < MaxRetries) && string.IsNullOrEmpty(result); i++) { + result = await UrlPostToContent(request, data, referer).ConfigureAwait(false); + } + + if (!string.IsNullOrEmpty(result)) { + return result; + } + + Logging.LogGenericWarning("Request failed even after " + MaxRetries + " tries", Identifier); + return null; + } + private async Task UrlGetToBytes(string request, string referer = null) { if (string.IsNullOrEmpty(request)) { Logging.LogNullError(nameof(request), Identifier); @@ -369,7 +388,7 @@ namespace ArchiSteamFarm { } } - private async Task UrlPost(string request, Dictionary data = null, string referer = null) { + private async Task UrlPost(string request, IEnumerable> data = null, string referer = null) { if (string.IsNullOrEmpty(request)) { Logging.LogNullError(nameof(request), Identifier); return false; @@ -380,7 +399,22 @@ namespace ArchiSteamFarm { } } - private async Task UrlPostToResponse(string request, Dictionary data = null, string referer = null) { + private async Task UrlPostToContent(string request, IEnumerable> data = null, string referer = null) { + if (string.IsNullOrEmpty(request)) { + Logging.LogNullError(nameof(request), Identifier); + return null; + } + + using (HttpResponseMessage httpResponse = await UrlPostToResponse(request, data, referer).ConfigureAwait(false)) { + if (httpResponse == null) { + return null; + } + + return await httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); + } + } + + private async Task UrlPostToResponse(string request, IEnumerable> data = null, string referer = null) { if (!string.IsNullOrEmpty(request)) { return await UrlRequest(request, HttpMethod.Post, data, referer).ConfigureAwait(false); } @@ -389,7 +423,7 @@ namespace ArchiSteamFarm { return null; } - private async Task UrlRequest(string request, HttpMethod httpMethod, Dictionary data = null, string referer = null) { + private async Task UrlRequest(string request, HttpMethod httpMethod, IEnumerable> data = null, string referer = null) { if (string.IsNullOrEmpty(request) || (httpMethod == null)) { Logging.LogNullError(nameof(request) + " || " + nameof(httpMethod), Identifier); return null; @@ -401,7 +435,7 @@ namespace ArchiSteamFarm { HttpResponseMessage responseMessage; using (HttpRequestMessage requestMessage = new HttpRequestMessage(httpMethod, request)) { - if ((data != null) && (data.Count > 0)) { + if (data != null) { try { requestMessage.Content = new FormUrlEncodedContent(data); } catch (UriFormatException e) {