Comments (4)
@shamooraee i made a lib which encapsulate NetCoreServer and and bring some features like serving both static files and rest api.
As reading you, it seems it can fit your needs
from netcoreserver.
I made this in OnRequestRecieved and it works...
if (request.Method == "HEAD")
SendResponseAsync(Response.MakeHeadResponse());
else if (request.Method == "GET" && request.Url == "/")
{
string responseString = @"
<html>
<body>
<form action='/' method='post'>
<label for='input1'>Input 1:</label>
<input type='text' id='input1' name='input1'><br><br>
<label for='input2'>Input 2:</label>
<input type='text' id='input2' name='input2'><br><br>
<input type='submit' value='Submit'>
</form>
</body>
</html>";
SendResponseAsync(Response.MakeGetResponse(responseString, "text/html; charset=UTF-8"));
}
else if ((request.Method == "POST") || (request.Method == "PUT"))
{
var body = request.Body;
var parameters = body.Split('&');
var input1 = WebUtility.UrlDecode(parameters[0].Split('=')[1]);
var input2 = WebUtility.UrlDecode(parameters[1].Split('=')[1]);
Response.Clear();
Response.SetBegin(302);
Response.SetHeader("Location", "/success");
Response.SetBody();
SendResponseAsync(Response);
}
else if (request.Url == "/success")
{
string responseString = @"
<html>
<body>
<h1>Form Submitted Successfully!</h1>
<p>Your data has been saved.</p>
</body>
</html>";
SendResponseAsync(Response.MakeGetResponse(responseString, "text/html; charset=UTF-8"));
}
else if (request.Method == "OPTIONS")
SendResponseAsync(Response.MakeOptionsResponse());
else if (request.Method == "TRACE")
SendResponseAsync(Response.MakeTraceResponse(request));
else
SendResponseAsync(Response.MakeErrorResponse("Unsupported HTTP method: " + request.Method));
from netcoreserver.
Got it working completely, thanks anyway! If you see any good things to consider in it let me know.
from netcoreserver.
@stratdev3 awesome! Thank you both!
Btw.. exactly my thoughts and why I am here at all: https://github.com/stratdev3/SimpleW?tab=readme-ov-file#the-existings-projects
from netcoreserver.
Related Issues (20)
- latency in reception of the first UDP frames (lazy?)
- Buffer.Reserve Wrong Condition? HOT 1
- TCP OnReceived(buffer, 0, received); HOT 1
- Cannot connect to WssChatServer for example
- TcpServer / TcpClient OptionKeepAlive have no effect HOT 2
- Cannot access a disposed object HOT 4
- Is there anyway to get WsOpcode in OnWsReceived?
- TcpSession.SendAsync() returns true even if a message fails to send. BytesSent also increases when send fails.
- lot of stupid internal definition
- Very good idea! Good luck!
- Ask a question about file service、
- Websocket server permessage-deflate compression support?
- WssSession is multithread??
- Can I capture the error information when the OnDisconnecting/OnDisconnected events are triggered? Because I need to capture the error information and handle it accordingly!
- OnDisconnecting after received message from client
- Linux - OutOfMemory exception
- Performance different from Readme. "TrySend() within Task" is why rollbacked?
- WssSession is multithread??
- How to OnReceived with Async?
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from netcoreserver.