本文整理汇总了C++中NPT_HttpEntity::Load方法的典型用法代码示例。如果您正苦于以下问题:C++ NPT_HttpEntity::Load方法的具体用法?C++ NPT_HttpEntity::Load怎么用?C++ NPT_HttpEntity::Load使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类NPT_HttpEntity
的用法示例。
在下文中一共展示了NPT_HttpEntity::Load方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: request
/*----------------------------------------------------------------------
| Test5
+---------------------------------------------------------------------*/
static bool
Test5(NPT_HttpUrl url)
{
NPT_LOG_INFO("########### TEST 5 ######################");
NPT_HttpClient client;
// first request
NPT_HttpRequest request(url, NPT_HTTP_METHOD_POST, NPT_HTTP_PROTOCOL_1_1);
NPT_HttpEntity* request_entity = new NPT_HttpEntity();
request_entity->SetInputStream("Testing");
request.SetEntity(request_entity);
NPT_HttpResponse* response = NULL;
client.SendRequest(request, response);
NPT_HttpEntity* entity = NULL;
if (response && (entity = response->GetEntity())) {
NPT_DataBuffer buffer;
if (NPT_FAILED(entity->Load(buffer))) return false;
}
// try again
delete response;
response = NULL;
request_entity = new NPT_HttpEntity();
request_entity->SetInputStream("Testing2");
request.SetEntity(request_entity);
client.SendRequest(request, response);
entity = NULL;
if (response && (entity = response->GetEntity())) {
NPT_DataBuffer buffer;
if (NPT_FAILED(entity->Load(buffer))) return false;
}
return true;
}
示例2: RecvHeaderData
bool CStreamCtrl::RecvHeaderData(NPT_HttpUrl url,NPT_DataBuffer& buffer)
{
NPT_HttpClient client;
NPT_String rdUrl=url.ToString();
// first request
NPT_HttpRequest request(url, NPT_HTTP_METHOD_GET, NPT_HTTP_PROTOCOL_1_1);
NPT_HttpResponse* response = NULL;
client.SendRequest(request, response);
NPT_HttpEntity* entity = NULL;
if (response && (entity = response->GetEntity())) {
if (NPT_FAILED(entity->Load(buffer))) return false;
}
else
return false;
return true;
}
示例3: RecvMediaData
bool CStreamCtrl::RecvMediaData(NPT_HttpUrl url,int in_nStartPos,
int in_nEndPos,NPT_DataBuffer& buffer)
{
NPT_HttpClient client;
NPT_String rdUrl=url.ToString();
// first request
NPT_HttpRequest request(url, NPT_HTTP_METHOD_GET, NPT_HTTP_PROTOCOL_1_1);
char range[100]={0};
sprintf(range," bytes=%d-%d",in_nStartPos,in_nEndPos-1);
request.GetHeaders().SetHeader(NPT_HTTP_HEADER_RANGE,range);
NPT_HttpResponse* response = NULL;
client.SendRequest(request, response);
NPT_HttpEntity* entity = NULL;
if (response && (entity = response->GetEntity())) {
if (NPT_FAILED(entity->Load(buffer))) return false;
}
else
return false;
return true;
}
示例4: standard_out
/*----------------------------------------------------------------------
| ShowResponse
+---------------------------------------------------------------------*/
static void
ShowResponse(NPT_HttpResponse* response, ShowMode mode)
{
// show response info
NPT_Debug("RESPONSE: protocol=%s, code=%d, reason=%s\n",
response->GetProtocol().GetChars(),
response->GetStatusCode(),
response->GetReasonPhrase().GetChars());
// show headers
NPT_HttpHeaders& headers = response->GetHeaders();
NPT_List<NPT_HttpHeader*>::Iterator header = headers.GetHeaders().GetFirstItem();
while (header) {
NPT_Debug("%s: %s\n",
(const char*)(*header)->GetName(),
(const char*)(*header)->GetValue());
++header;
}
// show entity
NPT_HttpEntity* entity = response->GetEntity();
if (entity != NULL) {
NPT_Debug("ENTITY: length=%lld, type=%s, encoding=%s\n",
entity->GetContentLength(),
entity->GetContentType().GetChars(),
entity->GetContentEncoding().GetChars());
switch (mode) {
case SHOW_MODE_LOAD: {
NPT_DataBuffer body;
NPT_Result result =entity->Load(body);
if (NPT_FAILED(result)) {
NPT_Debug("ERROR: failed to load entity (%d)\n", result);
} else {
NPT_Debug("BODY: loaded %d bytes\n", (int)body.GetDataSize());
// dump the body
NPT_OutputStreamReference output;
NPT_File standard_out(NPT_FILE_STANDARD_OUTPUT);
standard_out.Open(NPT_FILE_OPEN_MODE_WRITE);
standard_out.GetOutputStream(output);
NPT_Debug("%s", (char *)body.GetData());
// ÔÝʱ²»Ö§³Ö
// output->Write(body.GetData(), body.GetDataSize());
}
break;
}
case SHOW_MODE_STREAM_BLOCKING: {
NPT_DataBuffer buffer(4096);
NPT_Result result;
NPT_InputStreamReference input;
entity->GetInputStream(input);
do {
NPT_Size bytes_read = 0;
result = input->Read(buffer.UseData(), 4096, &bytes_read);
NPT_Debug("read %d bytes\n", bytes_read);
} while (NPT_SUCCEEDED(result));
break;
}
}
}
}