本文整理汇总了C++中HTTPServerResponse::begin方法的典型用法代码示例。如果您正苦于以下问题:C++ HTTPServerResponse::begin方法的具体用法?C++ HTTPServerResponse::begin怎么用?C++ HTTPServerResponse::begin使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类HTTPServerResponse
的用法示例。
在下文中一共展示了HTTPServerResponse::begin方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: 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
//.........这里部分代码省略.........