Skip to content

Commit 9dc4ef7

Browse files
committed
http client 增加了DebugLog
1 parent d5eb7fe commit 9dc4ef7

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

Helpers/SimApiHttpClient.cs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
namespace SimApi.Helpers;
1010

11-
public class SimApiHttpClient(string? appId, string appKey)
11+
public class SimApiHttpClient(string? appId, string appKey, bool debug = false)
1212
{
1313
public string Server { get; init; } = string.Empty;
1414
public string SignName { get; init; } = "sign";
@@ -17,7 +17,6 @@ public class SimApiHttpClient(string? appId, string appKey)
1717
public string? AppIdName { get; init; } = "appId";
1818
public string[] SignFields { get; init; } = [];
1919

20-
2120
public T? SignQuery<T>(string url, object? body = null, Dictionary<string, string>? queries = null)
2221
{
2322
url = Server + url;
@@ -68,7 +67,17 @@ public class SimApiHttpClient(string? appId, string appKey)
6867
private T? Query<T>(string url, object? req)
6968
{
7069
var http = new HttpClient();
70+
if (debug)
71+
{
72+
Console.WriteLine($"[HTTPCLIENT请求] {url}\n{SimApiUtil.Json(req)}\n");
73+
}
74+
7175
var resp = http.PostAsJsonAsync(url, req).Result;
76+
if (debug)
77+
{
78+
Console.WriteLine($"[HTTPCLIENT响应] {resp.Content.ReadAsStringAsync().Result}\n");
79+
}
80+
7281
var res = resp.Content.ReadFromJsonAsync<SimApiBaseResponse<T>>().Result;
7382
if (res == null)
7483
{

0 commit comments

Comments
 (0)