Skip to content

Commit efdd8cb

Browse files
committed
🐛 Bug fix for empty formdata when compile as AOT
1 parent a4f4346 commit efdd8cb

File tree

1 file changed

+8
-12
lines changed

1 file changed

+8
-12
lines changed

src/CloudlogHelper/Utils/QsoSyncAssistantUtil.cs

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -35,25 +35,21 @@ public class QsoSyncAssistantUtil
3535
public static async Task<IReadOnlyList<FlurlCookie>> LoginAndGetCookies(string baseurl, string username,
3636
string password, CancellationToken cancellationToken)
3737
{
38-
var tmp = new JsonObject();
39-
tmp.Add("user_name", username);
40-
tmp.Add("user_password", password);
41-
42-
var formData = tmp
43-
.ToDictionary(
44-
kvp => kvp.Key,
45-
kvp => kvp.Value?.ToString()
46-
);
47-
48-
4938
var loginRequest = baseurl
5039
.AllowHttpStatus(303)
5140
.WithAutoRedirect(false)
5241
.AppendPathSegments(DefaultConfigs.CloudlogLoginEndpoint);
5342

5443
var result = await loginRequest
55-
.PostUrlEncodedAsync(formData, default, cancellationToken).ConfigureAwait(false);
44+
.PostUrlEncodedAsync(new
45+
{
46+
user_name = username,
47+
user_password = password
48+
}, cancellationToken: cancellationToken)
49+
.ConfigureAwait(false);
50+
5651
var redirectUrl = result.Headers.FirstOrDefault("Location");
52+
if (redirectUrl is null) throw new InvalidOperationException("Username or password should not be empty!");
5753
if (!redirectUrl.Contains("dashboard")) throw new InvalidOperationException("Incorrect username or password");
5854
if (cancellationToken.IsCancellationRequested)
5955
throw new OperationCanceledException("Operation(LoginAndGetCookies) was canceled.");

0 commit comments

Comments
 (0)