本文整理汇总了C++中NPT_HttpRequest::Emit方法的典型用法代码示例。如果您正苦于以下问题:C++ NPT_HttpRequest::Emit方法的具体用法?C++ NPT_HttpRequest::Emit怎么用?C++ NPT_HttpRequest::Emit使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类NPT_HttpRequest
的用法示例。
在下文中一共展示了NPT_HttpRequest::Emit方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: packet
/*----------------------------------------------------------------------
| PLT_SsdpSender::SendSsdp
+---------------------------------------------------------------------*/
NPT_Result
PLT_SsdpSender::SendSsdp(NPT_HttpRequest& request,
const char* usn,
const char* target,
NPT_UdpSocket& socket,
bool notify,
const NPT_SocketAddress* addr /* = NULL */)
{
NPT_CHECK_SEVERE(FormatPacket(request, usn, target, socket, notify));
// logging
NPT_LOG_FINE("Sending SSDP:");
PLT_LOG_HTTP_MESSAGE(NPT_LOG_LEVEL_FINE, &request);
// use a memory stream to write all the data
NPT_MemoryStream stream;
NPT_Result res = request.Emit(stream);
if (NPT_FAILED(res)) return res;
// copy stream into a data packet and send it
NPT_LargeSize size;
stream.GetSize(size);
if (size != (NPT_Size)size) return NPT_ERROR_OUT_OF_RANGE;
NPT_DataBuffer packet(stream.GetData(), (NPT_Size)size);
return socket.Send(packet, addr);
}
示例2: packet
/*----------------------------------------------------------------------
| PLT_SsdpSender::SendSsdp
+---------------------------------------------------------------------*/
NPT_Result
PLT_SsdpSender::SendSsdp(NPT_HttpRequest& request,
const char* usn,
const char* target,
NPT_UdpSocket& socket,
bool notify,
const NPT_SocketAddress* addr /* = NULL */)
{
NPT_CHECK_SEVERE(FormatPacket(request, usn, target, socket, notify));
// logging
NPT_String prefix = NPT_String::Format("Sending SSDP %s packet for %s",
(const char*)request.GetMethod(),
usn);
PLT_LOG_HTTP_MESSAGE(NPT_LOG_LEVEL_FINER, prefix, &request);
// use a memory stream to write all the data
NPT_MemoryStream stream;
NPT_Result res = request.Emit(stream);
NPT_CHECK(res);
// copy stream into a data packet and send it
NPT_LargeSize size;
stream.GetSize(size);
if (size != (NPT_Size)size) NPT_CHECK(NPT_ERROR_OUT_OF_RANGE);
NPT_DataBuffer packet(stream.GetData(), (NPT_Size)size);
NPT_CHECK_WARNING(socket.Send(packet, addr));
return NPT_SUCCESS;
}
示例3:
/*----------------------------------------------------------------------
| PLT_HttpClient::SendRequest
+---------------------------------------------------------------------*/
NPT_Result
PLT_HttpClient::SendRequest(NPT_OutputStreamReference& output_stream,
NPT_HttpRequest& request,
NPT_Timeout timeout)
{
NPT_COMPILER_UNUSED(timeout);
// connect to the server
NPT_LOG_FINE("Sending:");
PLT_LOG_HTTP_MESSAGE(NPT_LOG_LEVEL_FINE, &request);
// add any headers that may be missing
NPT_HttpHeaders& headers = request.GetHeaders();
//headers.SetHeader(NPT_HTTP_HEADER_CONNECTION, "close");
if (!headers.GetHeader(NPT_HTTP_HEADER_USER_AGENT)) {
headers.SetHeader(NPT_HTTP_HEADER_USER_AGENT,
"Platinum/" PLT_PLATINUM_VERSION_STRING);
}
// set host only if not already set
if (!headers.GetHeader(NPT_HTTP_HEADER_HOST)) {
NPT_String host = request.GetUrl().GetHost();
if (request.GetUrl().GetPort() != NPT_HTTP_DEFAULT_PORT) {
host += ":";
host += NPT_String::FromInteger(request.GetUrl().GetPort());
}
headers.SetHeader(NPT_HTTP_HEADER_HOST, host);
}
// get the request entity to set additional headers
NPT_InputStreamReference body_stream;
NPT_HttpEntity* entity = request.GetEntity();
if (entity && NPT_SUCCEEDED(entity->GetInputStream(body_stream))) {
// content length
headers.SetHeader(NPT_HTTP_HEADER_CONTENT_LENGTH,
NPT_String::FromInteger(entity->GetContentLength()));
// content type
NPT_String content_type = entity->GetContentType();
if (!content_type.IsEmpty()) {
headers.SetHeader(NPT_HTTP_HEADER_CONTENT_TYPE, content_type);
}
// content encoding
NPT_String content_encoding = entity->GetContentEncoding();
if (!content_encoding.IsEmpty()) {
headers.SetHeader(NPT_HTTP_HEADER_CONTENT_ENCODING, content_encoding);
}
} else {
// force content length to 0 is there is no message body
headers.SetHeader(NPT_HTTP_HEADER_CONTENT_LENGTH, "0");
}
// create a memory stream to buffer the headers
NPT_MemoryStream header_stream;
// emit the request headers into the header buffer
request.Emit(header_stream);
// send the headers
NPT_CHECK_SEVERE(output_stream->WriteFully(header_stream.GetData(), header_stream.GetDataSize()));
// send request body
if (!body_stream.IsNull() && entity->GetContentLength()) {
NPT_CHECK_SEVERE(NPT_StreamToStreamCopy(*body_stream.AsPointer(), *output_stream.AsPointer()));
}
// flush the output stream so that everything is sent to the server
output_stream->Flush();
return NPT_SUCCESS;
}