Sending plain text for a given path (WResource?)
Added by soratobu kuroneko almost 13 years ago
Hello,
I'm new to Wt, I'm trying to implement the "Perform update" of dyndns (http://dyn.com/support/developers/api/perform-update/) with Wt.
In brief, client will send GET request to http://server/nic/update, process them, doing authentification and some DB queries, and then sending back to the client a text/html mime type document with just one word in the HTTP response body. For example:
HTTP/1.1 403 Forbidden
onnection: Keep-Alive
Content-Length: 7
Date: Tue, 10 Jan 2012 09:48:28 GMT
Content-Type: text/html; charset=iso-8859-1
Server: Apache
badauth
I think I should use WResource and WServer::addResource, but I can't get it works. I tried the following code:
HelloWorld::HelloWorld(const Wt::WEnvironment& env)
: Wt::WApplication(env)
{
MyResource *resource = new MyResource(this);
resource->suggestFileName("update");
environment().server()->addResource(resource, "/nic/update");
}
but accessing /nic/update gives me a 404 error...
Could anybody give me some idea how to implement that?
Thank you
Replies (2)
RE: Sending plain text for a given path (WResource?) - Added by Koen Deforche almost 13 years ago
Hey,
I think you've got it almost right, however, you are now adding a static resource in the constructor of your application, which corresponds to a single session. This is probably not what you want, since this would add the same static resource over and over for each session, and also (which I think is why it doesn't work in your case), the resource will not work until at least one session has started.
In your case, you should probably consider something like this (see also examples/blog/blog.C where an RSS feed is deployed as a static resource):
int main(int argc, char **argv)
{
try {
WServer server(argv[0]);
server.setServerConfiguration(argc, argv, WTHTTP_CONFIGURATION);
BlogSession::configureAuth();
MyResource resource;
server.addResource(&resource, "/nic/update");
if (server.start()) {
WServer::waitForShutdown();
server.stop();
}
} catch (WServer::Exception& e) {
std::cerr << e.what() << std::endl;
} catch (std::exception &e) {
std::cerr << "exception: " << e.what() << std::endl;
}
}
RE: Sending plain text for a given path (WResource?) - Added by soratobu kuroneko almost 13 years ago
Thank you very much!