本文整理汇总了C++中HTTPServerRequest::getMethod方法的典型用法代码示例。如果您正苦于以下问题:C++ HTTPServerRequest::getMethod方法的具体用法?C++ HTTPServerRequest::getMethod怎么用?C++ HTTPServerRequest::getMethod使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类HTTPServerRequest
的用法示例。
在下文中一共展示了HTTPServerRequest::getMethod方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: handleRequest
virtual void handleRequest(HTTPServerRequest &req, HTTPServerResponse &resp){
resp.setStatus(HTTPResponse::HTTP_OK);
resp.setContentType("text/html");
// Generate requested HTML file
ostream& out = resp.send();
out << "<h1>Hello world! This files name is " << req.getURI() << "</h1>"
<< "<p>Host: " << req.getHost() << "</p>"
<< "<p>Method: " << req.getMethod() << "</p>";
out.flush();
cout << endl << "Client requested: =" << req.getURI() << endl;
}
示例2: handleRequest
void handleRequest(HTTPServerRequest& request, HTTPServerResponse& response)
{
HTMLForm form(request, request.stream());
response.setContentType("text/html");
response.setChunkedTransferEncoding(true);
std::ostream& ostr = response.send();
URI requestURI(request.getURI());
ostr << "<html><head><title>Echo HTTP Headers and HTML Form Information</title>"
"<link rel=\"stylesheet\" href=\"css/styles.css\" type=\"text/css\"/></head><body>"
"<div class=\"header\">"
"<h1 class=\"category\">Open Service Platform</h1>"
"<h1 class=\"title\">Echo HTTP Headers and HTML Form Information</H1>"
"</div>"
"<div class=\"body\">";
// echo the items available by method
ostr << "<h2>Request</h2>"
<< "<ul>"
<< "<li><b>Method:</b> " << request.getMethod() << "</li>"
<< "<li><b>URI Path:</b> " << requestURI.getPath() << "</li>"
<< "<li><b>URI Query:</b> " << requestURI.getQuery() << "</li>"
<< "<li><b>HTTP Version:</b> " << request.getVersion() << "</li>"
<< "<li><b>Host:</b> " << request.getHost() << "</li>"
<< "<li><b>Content Type:</b> " << request.getContentType() << "</li>"
<< "<li><b>Chunked:</b> " << (request.getChunkedTransferEncoding() ? "true" : "false") << "</li>"
<< "<li><b>Keep Alive:</b> " << (request.getKeepAlive() ? "true" : "false") << "</li>"
<< "<li><b>Transfer Encoding:</b> " << request.getTransferEncoding() << "</li>"
<< "<li><b>Client Address:</b> " << request.clientAddress().toString() << "</li>";
if (request.hasContentLength())
{
ostr << "<li><b>Content Length:</b> " << request.getContentLength64() << "</li>";
}
ostr << "</ul>";
// echo the request headers
{
ostr << "<hr>"
"<h2>Request Headers</h2><ul>\n";
NameValueCollection headers;
NameValueCollection::ConstIterator itr(request.begin());
NameValueCollection::ConstIterator itrEnd(request.end());
for (; itr != itrEnd; ++itr)
{
ostr << "<li><b>" << htmlize(itr->first) << "</b>: " << htmlize(itr->second) << "</li>";
}
ostr << "</ul>";
}
// echo any cookies
{
NameValueCollection cookies;
request.getCookies(cookies);
if (!cookies.empty())
{
ostr << "<hr>";
ostr << "<h2>Cookies</h2><ul>\n";
NameValueCollection::ConstIterator itr(cookies.begin());
NameValueCollection::ConstIterator itrEnd(cookies.end());
for (; itr != itrEnd; ++itr)
{
ostr << "<li><b>" << htmlize(itr->first) << "</b>: " << htmlize(itr->second) << "</li>";
}
ostr << "</ul>";
}
}
// echo any form data (GETs or POSTs)
if (!form.empty())
{
ostr << "<hr>"
"<h2>Form Data</h2><ul>\n";
NameValueCollection::ConstIterator itr(form.begin());
NameValueCollection::ConstIterator itrEnd(form.end());
for (; itr != itrEnd; ++itr)
{
ostr << "<li><b>" << htmlize(itr->first) << "</b>: " << htmlize(itr->second) << "</li>\n";
}
ostr << "</ul>";
}
ostr << "<hr>"
<< "<h2>Response</h2>"
<< "<ul>"
<< "<li><b>Status:</b> " << response.getStatus() << "</li>"
<< "<li><b>Reason:</b> " << response.getReason() << "</li>"
<< "</ul>";
// echo the response headers
//.........这里部分代码省略.........
示例3: handleRequest
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";
}