void handleRequest(HTTPServerRequest& request, HTTPServerResponse& response) { Application& app = Application::instance(); app.logger().information("Request from " + request.clientAddress().toString()); MyPartHandler partHandler; HTMLForm form(request, request.stream(), partHandler); response.setChunkedTransferEncoding(true); response.setContentType("text/html"); std::ostream& ostr = response.send(); ostr << "<html>\n" "<head>\n" "<title>POCO Form Server Sample</title>\n" "</head>\n" "<body>\n" "<h1>POCO Form Server Sample</h1>\n" "<h2>GET Form</h2>\n" "<form method=\"GET\" action=\"/form\">\n" "<input type=\"text\" name=\"text\" size=\"31\">\n" "<input type=\"submit\" value=\"GET\">\n" "</form>\n" "<h2>POST Form</h2>\n" "<form method=\"POST\" action=\"/form\">\n" "<input type=\"text\" name=\"text\" size=\"31\">\n" "<input type=\"submit\" value=\"POST\">\n" "</form>\n" "<h2>File Upload</h2>\n" "<form method=\"POST\" action=\"/form\" enctype=\"multipart/form-data\">\n" "<input type=\"file\" name=\"file\" size=\"31\"> \n" "<input type=\"submit\" value=\"Upload\">\n" "</form>\n"; ostr << "<h2>Request</h2><p>\n"; ostr << "Method: " << request.getMethod() << "<br>\n"; ostr << "URI: " << request.getURI() << "<br>\n"; NameValueCollection::ConstIterator it = request.begin(); NameValueCollection::ConstIterator end = request.end(); for (; it != end; ++it) { ostr << it->first << ": " << it->second << "<br>\n"; } ostr << "</p>"; if (!form.empty()) { ostr << "<h2>Form</h2><p>\n"; it = form.begin(); end = form.end(); for (; it != end; ++it) { ostr << it->first << ": " << it->second << "<br>\n"; } ostr << "</p>"; } if (!partHandler.name().empty()) { ostr << "<h2>Upload</h2><p>\n"; ostr << "Name: " << partHandler.name() << "<br>\n"; ostr << "File Name: " << partHandler.fileName() << "<br>\n"; ostr << "Type: " << partHandler.contentType() << "<br>\n"; ostr << "Size: " << partHandler.length() << "<br>\n"; ostr << "</p>"; } ostr << "</body>\n"; }
void handleRequest(Poco::Net::HTTPServerRequest& request, Poco::Net::HTTPServerResponse& response) { //Poco::Util::Application& app = Poco::Util::Application::instance(); //app.logger().information("Request from " + request.clientAddress().toString()); std::cout << "Request from " << request.clientAddress().toString() << std::endl; MyPartHandler partHandler; Poco::Net::HTMLForm form(request, request.stream(), partHandler); std::string spinToken, sceneString, nodeString, args; std::istringstream pathstream(request.getURI()); pathstream.get(); // ignore leading slash getline(pathstream, spinToken, '/'); getline(pathstream, sceneString, '/'); getline(pathstream, nodeString, '?'); if (sceneString.empty()) sceneString = "default"; //if (nodeString.empty()) nodeString = "shp"; if (form.empty()) args = "createNode shp ShapeNode"; else args = form["args"]; response.setChunkedTransferEncoding(true); response.setContentType("text/html"); std::ostream& ostr = response.send(); ostr << "<html>\n" "<head>\n" "<title>SPIN Web Service</title>\n" "</head>\n" "<body>\n" "<h1>SPIN Web Service</h1>\n" "<h3>Enter a SPIN command in the form below:</h3>\n" "<table><tr><td nowrap=\"nowrap\">\n" "<form name=\"urlForm\" method=\"GET\" action=\"null\">\n" "/SPIN/" "<input type=\"text\" name=\"sceneID\" value=\"" << sceneString << "\" size=\"10\">\n" "/<input type=\"text\" name=\"nodeID\" value=\"" << nodeString << "\" size=\"10\">" "</form></td>\n" "<td nowrap=\"nowrap\">\n" "<form name=\"spinform\" method=\"GET\" action=\"null\">\n" "<input type=\"text\" name=\"args\" value=\"" << args << "\" size=\"20\">\n" "<input type=\"submit\" value=\"GO\" onclick=\"this.form.action='/SPIN/'+document.forms['urlForm']['sceneID'].value+'/'+document.forms['urlForm']['nodeID'].value\">\n" "</form>\n" "</tr></table>\n" "<p>(NOTE: you can send scene messages by leaving the node name blank)</p>\n" "\n"; /* ostr << "<html>\n" "<head>\n" "<title>SPIN Web Server Sample</title>\n" "</head>\n" "<body>\n" "<h1>SPIN Web Server Sample</h1>\n" "<h2>Tests:</h2>\n" "<form name=\"spinform\" method=\"GET\" action=\"null\">\n" "/SPIN/default/" "<input type=\"text\" name=\"nodeID\" value=\"shp\" size=\"15\">" " " "<input type=\"text\" name=\"method\" value=\"rotate\" size=\"15\">" " move<input type=\"text\" name=\"x\" value=\"0\" size=\"3\">" " <input type=\"text\" name=\"y\" value=\"0\" size=\"3\">" " <input type=\"text\" name=\"z\" value=\"10\" size=\"3\">\n" " <input type=\"submit\" value=\"GO\" onclick=\"this.form.action='/SPIN/default/'+this.form.nodeID.value\">\n" "</form>\n" "\n"; ostr << "<html>\n" "<head>\n" "<title>SPIN Web Server Sample</title>\n" "</head>\n" "<body>\n" "<h1>SPIN Web Server Sample</h1>\n" "<h2>GET Form</h2>\n" "<form method=\"GET\" action=\"/form\">\n" "<input type=\"text\" name=\"text\" size=\"31\">\n" "<input type=\"submit\" value=\"GET\">\n" "</form>\n" "<h2>POST Form</h2>\n" "<form method=\"POST\" action=\"/form\">\n" "<input type=\"text\" name=\"text\" size=\"31\">\n" "<input type=\"submit\" value=\"POST\">\n" "</form>\n" "<h2>File Upload</h2>\n" "<form method=\"POST\" action=\"/form\" enctype=\"multipart/form-data\">\n" "<input type=\"file\" name=\"file\" size=\"31\"> \n" "<input type=\"submit\" value=\"Upload\">\n" "</form>\n"; */ ostr << "<h2>Result</h2><p>\n"; ostr << "Method: " << request.getMethod() << "<br>\n"; ostr << "URI: " << request.getURI() << "<br>\n"; Poco::Net::NameValueCollection::ConstIterator it = request.begin(); Poco::Net::NameValueCollection::ConstIterator end = request.end(); for (; it != end; ++it) { ostr << it->first << ": " << it->second << "<br>\n"; } ostr << "</p>"; /* if (!form.empty()) { ostr << "<h2>Result</h2><p>\n"; it = form.begin(); end = form.end(); for (; it != end; ++it) { ostr << it->first << ": " << it->second << "<br>\n"; } ostr << "</p>"; } */ // --------parse introspect_invoke(request.getURI(), form); // --------------- if (!partHandler.name().empty()) { ostr << "<h2>Upload</h2><p>\n"; ostr << "Name: " << partHandler.name() << "<br>\n"; ostr << "File Name: " << partHandler.fileName() << "<br>\n"; ostr << "Type: " << partHandler.contentType() << "<br>\n"; ostr << "Size: " << partHandler.length() << "<br>\n"; ostr << "</p>"; } ostr << "</body>\n"; }