Windows Phone Http Server
This project is contains the required source code to run a http server on your windows phone 8 app.
Example how to use the http server to send an sms:
// create the http server
HttpServer httpServer = new HttpServer("192.168.2.102");
// register an request handler which will handle the posted form data
httpServer.RegisterRequestHandler(new Regex("/sendSms"), request =>
{
// get the data send as form data
FormDataContentProvider formDataProvider = request.Content as FormDataContentProvider;
// read the data from the form
string number = formDataProvider.FormData["number"];
string message = formDataProvider.FormData["message"];
// use the windows phone SMS api to send a SMS
SmsComposeTask smsTask = new SmsComposeTask();
smsTask.To = number;
smsTask.Body = message;
smsTask.Show();
// tell the client, that everything went fine
return new HttpResponse(HttpStatusCode.Ok);
});
The server also has support for static content such as images, which are handled by a resource manager:
// create the http server
HttpServer httpServer = new HttpServer("192.168.2.102");
// create a resource manager and set the base path
httpServer.ResourceManager = new ResourceManager("webserver");
// add an resource to the resource manager
httpServer.ResourceManager.RegisterResource(
"/images/animals/dog.png", // the internal path, relative to the base path to determine the data
"/images/dog"); // the external path the resource will be reachable at
// (eg http://192.168.2.102/images/dog will serve
// the /webserver/images/animals/dog.png)