HTTPServer embarqué et paramètres
Bonjour à tous,
newbee en C#, j'essaie de réaliser un serveur web "embarqué" à partir de cet exemple :
http://www.codeproject.com/KB/IP/CSh...TTPServer.aspx
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57
| using System;
using System.IO;
using System.Text;
using System.Diagnostics;
using HybridDSP.Net.HTTP;
namespace ExampleServer
{
class DateTimeHandler : IHTTPRequestHandler
{
private RequestHandlerFactory.WriteLogDelegate _writeLogDelegate;
public DateTimeHandler(RequestHandlerFactory.WriteLogDelegate d)
{
_writeLogDelegate = d;
}
#region IHTTPRequestHandler Members
public void HandleRequest(HTTPServerRequest request, HTTPServerResponse response)
{
if (_writeLogDelegate != null)
_writeLogDelegate("Handling DateTime request");
if (request.URI == "/")
{
/**
* In this example we'll write the body into the
* stream obtained by response.Send(). This will cause the
* KeepAlive to be false since the size of the body is not
* known when the response header is sent.
**/
response.ContentType = "text/html";
using (Stream ostr = response.Send())
using (TextWriter tw = new StreamWriter(ostr))
{
tw.WriteLine("<html>");
tw.WriteLine("<head>");
tw.WriteLine("<title>Date Time Server</title>");
tw.WriteLine("<meta http-equiv=\"refresh\" content=\"2\">");
tw.WriteLine("</header>");
tw.WriteLine("<body>");
tw.WriteLine(DateTime.Now.ToString());
tw.WriteLine("</body>");
tw.WriteLine("</html>");
}
}
else
{
response.StatusAndReason = HTTPServerResponse.HTTPStatus.HTTP_NOT_FOUND;
response.Send();
}
}
#endregion
}
} |
ce code utilise la classe HTTPServerRequest pour envoyer des requêtes au serveur.
L'exemple montre un appel "http://localhost:8080"
Mon souci est que je souhaite envoyer des paramètres au serveur avec un nom de méthode, et plusieurs paramètres comment procéder ?
puis je les passer dans l'URI ? comment les filtrer ? dans le code ?
Merci par avance,
Christophe