Merge
This commit is contained in:
parent
bd14722791
commit
2828fec316
@ -113,15 +113,23 @@ public partial class Server : GlobalBase
|
||||
if (!request.HasEntityBody)
|
||||
{
|
||||
Log("No request body");
|
||||
Dictionary<string, string> emptyBody = new();
|
||||
return emptyBody;
|
||||
return new Dictionary<string, string>();
|
||||
}
|
||||
Stream body = request.InputStream;
|
||||
Encoding encoding = request.ContentEncoding;
|
||||
StreamReader reader = new StreamReader(body, encoding);
|
||||
string s = reader.ReadToEnd();
|
||||
Dictionary<string, string> requestBody = JsonConvert.DeserializeObject<Dictionary<string, string>>(s);
|
||||
return requestBody;
|
||||
using StreamReader streamReader = new (body, encoding);
|
||||
try
|
||||
{
|
||||
Dictionary<string, string> requestBody =
|
||||
JsonConvert.DeserializeObject<Dictionary<string, string>>(streamReader.ReadToEnd())
|
||||
?? new();
|
||||
return requestBody;
|
||||
}
|
||||
catch (JsonException e)
|
||||
{
|
||||
Log(e.Message);
|
||||
}
|
||||
return new Dictionary<string, string>();
|
||||
}
|
||||
|
||||
private void HandleGet(HttpListenerRequest request, HttpListenerResponse response)
|
||||
|
@ -1,7 +1,5 @@
|
||||
using System.Net;
|
||||
using System.Text;
|
||||
using System.Text.RegularExpressions;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace Tranga;
|
||||
|
||||
@ -29,30 +27,6 @@ public partial class Server
|
||||
SendResponse(responseMessage.Item1, response, responseMessage.Item2);
|
||||
}
|
||||
|
||||
private Dictionary<string, string> GetRequestBody(HttpListenerRequest request)
|
||||
{
|
||||
if (!request.HasEntityBody)
|
||||
{
|
||||
Log("No request body");
|
||||
return new Dictionary<string, string>();
|
||||
}
|
||||
Stream body = request.InputStream;
|
||||
Encoding encoding = request.ContentEncoding;
|
||||
using StreamReader streamReader = new (body, encoding);
|
||||
try
|
||||
{
|
||||
Dictionary<string, string> requestBody =
|
||||
JsonConvert.DeserializeObject<Dictionary<string, string>>(streamReader.ReadToEnd())
|
||||
?? new();
|
||||
return requestBody;
|
||||
}
|
||||
catch (JsonException e)
|
||||
{
|
||||
Log(e.Message);
|
||||
}
|
||||
return new Dictionary<string, string>();
|
||||
}
|
||||
|
||||
private ValueTuple<HttpStatusCode, object?> HandleGetV2(string path, HttpListenerResponse response,
|
||||
Dictionary<string, string> requestParameters)
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user