Created
April 19, 2024 11:06
-
-
Save Sighyu/ea090a71271e01036ad5c12379da911e to your computer and use it in GitHub Desktop.
better besthttp logging modify BestHTTP.HTTPRequest.CallCallback method in with dnspy and add this
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
internal void CallCallback() | |
{ | |
try | |
{ | |
if (this.Callback != null) | |
{ | |
this.Callback(this, this.Response); | |
} | |
} | |
catch (Exception ex) | |
{ | |
HTTPManager.Logger.Exception("HTTPRequest", "CallCallback", ex); | |
} finally | |
{ | |
LogRequestAndResponse(); | |
} | |
} | |
private void LogRequestAndResponse() | |
{ | |
using (StreamWriter writer = new StreamWriter(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "HTTPRequestLog.txt"), true)) | |
{ | |
writer.WriteLine("Request Time: " + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")); | |
TextWriter textWriter = writer; | |
string text = "Request URL: "; | |
Uri currentUri = this.CurrentUri; | |
textWriter.WriteLine(text + ((currentUri != null) ? currentUri.ToString() : null)); | |
writer.WriteLine("Request Method: " + HTTPRequest.MethodNames[(int)this.MethodType]); | |
writer.WriteLine("Request Headers: "); | |
foreach (KeyValuePair<string, List<string>> header in this.Headers) | |
{ | |
foreach (string value in header.Value) | |
{ | |
writer.WriteLine(header.Key + ": " + value); | |
} | |
} | |
byte[] requestBody = this.GetEntityBody(); | |
if (requestBody != null) | |
{ | |
writer.WriteLine("Request Body: " + Encoding.UTF8.GetString(requestBody)); | |
} | |
if (this.Response != null) | |
{ | |
writer.WriteLine("Response Status Code: " + this.Response.StatusCode.ToString()); | |
writer.WriteLine("Response Headers: "); | |
foreach (KeyValuePair<string, List<string>> header2 in this.Response.Headers) | |
{ | |
writer.WriteLine(string.Format("{0}: {1}", header2.Key, string.Join(", ", header2.Value))); | |
} | |
if (this.Response.Data != null) | |
{ | |
writer.WriteLine("Response Body: " + Encoding.UTF8.GetString(this.Response.Data)); | |
} | |
} | |
writer.WriteLine("--------------------------------------------------"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment