REST-Service - curl results into 404 Not Found
Added by Claudio White about 7 years ago
I start my WebService from Visual Studio Debug with following commands:
---docroot . ---http-address 0.0.0.0 ---http-port 8095 ---config C:/Dev/wt336_15/projects/MyResource/wt_config.xml
MyCode:
...
#ifndef WT_WIN32
extern char **environ;
#endif // WT_WIN32
class PlaintextResource : public Wt::WResource {
virtual void handleRequest(const Wt::Http::Request &request, Wt::Http::Response &response) {
string pathinfo = request.pathInfo();
const std::istream &input = request.in();
response.setMimeType("text/plain");
response.addHeader("Server", "Wt");
response.out() << "Hello, this is MyResource speaking!";
}
};
int main(int argc, char **argv)
{
try {
Wt::WServer server(argv[0]);
server.setServerConfiguration(argc, argv, WTHTTP_CONFIGURATION);
PlaintextResource plaintextResource;
server.addResource(&plaintextResource, "/");
if (server.start())
{
int sig = Wt::WServer::waitForShutdown();
std::cerr << "Shutdown (signal = " << sig << ")" << std::endl;
server.stop();
#ifndef WT_WIN32
if (sig == SIGHUP)
Wt::WServer::restart(argc, argv, environ);
#endif // WT_WIN32
}
}
catch (Wt::WServer::Exception& e) {
std::cerr << e.what() << "\n";
return 1;
}
catch (std::exception& e) {
std::cerr << "exception: " << e.what() << "\n";
return 1;
}
catch (...) {
std::cerr << "exception: unknown" << "\n";
return 1;
}
}
return 0;
}
When i call my URL with curl i get an 404 Not found error as result - this is the call:
curl http://localhost:8095/
This is the result:
Not Found
404 Not Found
And in the WT-Serverconsole: "GET / HTTP/1.1" 404 85
I did Change my Hosts file and add the local ip as myserver.com and called again as:
curl http://myserver.com:8095/
But the result is the same:
Not Found
404 Not Found
I tried it with the following too:
curl -X POST -d @Temp.txt http://localhost:8095 ---header "Content-Type:text/text"
But the result is the same:
Not Found
404 Not Found
And in the WT-Serverconsole: "POST / HTTP/1.1" 404 85
Has anyone an idea what goes wrong here?
Thanks in advance for answers hopefully :-)
P.S. I am using WT 3.3.6 in 32Bit Mode compiled with Visual Studio 2015 (currently i cannot upgrade to newest Version).
Replies (3)
RE: REST-Service - curl results into 404 Not Found - Added by Roel Standaert about 7 years ago
I'm guessing this is a misconfiguration in your wt_config.xml somewhere, because that works just fine.
Note: that snippet, even with the appropriate headers added, does not compile because the curly brackets in the main function are not balanced.
Of course, if it turns out to be a bug in Wt 3.3.6 you'll have no choice but to update.
RE: REST-Service - curl results into 404 Not Found - Added by Claudio White about 7 years ago
Thanks..i will a look to the wt_config.
I did edit the snippet from comments and so on...in the original it is compiling:-)
RE: REST-Service - curl results into 404 Not Found - Added by Claudio White about 7 years ago
Ok...i found the failure...once again it was my mistake...in the original code i have an if/else and does not really start the REST-Server instead i started Wt::WRun:-(