本文整理汇总了C++中Network::GetRequest方法的典型用法代码示例。如果您正苦于以下问题:C++ Network::GetRequest方法的具体用法?C++ Network::GetRequest怎么用?C++ Network::GetRequest使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Network
的用法示例。
在下文中一共展示了Network::GetRequest方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: SendJsonResponse
void Webserver::SendJsonResponse(const char* command)
{
Network *net = reprap.GetNetwork();
RequestState *req = net->GetRequest(NULL);
bool keepOpen = false;
bool mayKeepOpen;
if (numQualKeys == 0)
{
mayKeepOpen = GetJsonResponse(command, "", "", 0);
}
else
{
mayKeepOpen = GetJsonResponse(command, qualifiers[0].key, qualifiers[0].value, qualifiers[1].key - qualifiers[0].value - 1);
}
if (mayKeepOpen)
{
// Check that the browser wants to persist the connection too
for (size_t i = 0; i < numHeaderKeys; ++i)
{
if (StringEquals(headers[i].key, "Connection"))
{
// Comment out the following line to disable persistent connections
keepOpen = StringEquals(headers[i].value, "keep-alive");
break;
}
}
}
req->Write("HTTP/1.1 200 OK\n");
req->Write("Content-Type: application/json\n");
req->Printf("Content-Length: %u\n", strlen(jsonResponse));
req->Printf("Connection: %s\n\n", keepOpen ? "keep-alive" : "close");
req->Write(jsonResponse);
net->SendAndClose(NULL, keepOpen);
}
示例2: SendFile
// Start sending a file or a JSON response.
void Webserver::SendFile(const char* nameOfFileToSend)
{
if (StringEquals(nameOfFileToSend, "/"))
{
nameOfFileToSend = INDEX_PAGE;
}
FileStore *fileToSend = platform->GetFileStore(platform->GetWebDir(), nameOfFileToSend, false);
if (fileToSend == NULL)
{
nameOfFileToSend = FOUR04_FILE;
fileToSend = platform->GetFileStore(platform->GetWebDir(), nameOfFileToSend, false);
if (fileToSend == NULL)
{
RejectMessage("not found", 404);
return;
}
}
Network *net = reprap.GetNetwork();
RequestState *req = net->GetRequest(NULL);
req->Write("HTTP/1.1 200 OK\n");
const char* contentType;
bool zip = false;
if (StringEndsWith(nameOfFileToSend, ".png"))
{
contentType = "image/png";
}
else if (StringEndsWith(nameOfFileToSend, ".ico"))
{
contentType = "image/x-icon";
}
else if (StringEndsWith(nameOfFileToSend, ".js"))
{
contentType = "application/javascript";
}
else if (StringEndsWith(nameOfFileToSend, ".css"))
{
contentType = "text/css";
}
else if (StringEndsWith(nameOfFileToSend, ".htm") || StringEndsWith(nameOfFileToSend, ".html"))
{
contentType = "text/html";
}
else if (StringEndsWith(nameOfFileToSend, ".zip"))
{
contentType = "application/zip";
zip = true;
}
else
{
contentType = "application/octet-stream";
}
req->Printf("Content-Type: %s\n", contentType);
if (zip && fileToSend != NULL)
{
req->Write("Content-Encoding: gzip\n");
req->Printf("Content-Length: %lu", fileToSend->Length());
}
req->Write("Connection: close\n\n");
net->SendAndClose(fileToSend);
}