本文整理汇总了C++中HttpMessage::insertHeaderField方法的典型用法代码示例。如果您正苦于以下问题:C++ HttpMessage::insertHeaderField方法的具体用法?C++ HttpMessage::insertHeaderField怎么用?C++ HttpMessage::insertHeaderField使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类HttpMessage
的用法示例。
在下文中一共展示了HttpMessage::insertHeaderField方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: testHeader
/**
* Test header
*/
void testHeader()
{
const char* name1 = "yyy";
const char* value1 = "yyy-value";
const char* valueRef = NULL;
const char* name2 = "yyy1";
const char* value2 = "yyy-value1";
const char* value2a = "yyy-value2";
const char* value2b = "yyy-value3";
UtlBoolean rc;
HttpMessage *msg;
msg = new HttpMessage();
// H E A D E R
int fieldCount = msg->getCountHeaderFields();
CPPUNIT_ASSERT_EQUAL_MESSAGE("field count should be zero",
0, fieldCount);
// add header field name1
msg->addHeaderField(name1, value1);
// get overall header field count
fieldCount = msg->getCountHeaderFields();
CPPUNIT_ASSERT_EQUAL_MESSAGE("field count should be zero", 1,
fieldCount);
// get header field count for name1
fieldCount = msg->getCountHeaderFields(name1);
CPPUNIT_ASSERT_EQUAL_MESSAGE("field count should be zero", 1,
fieldCount);
// get header field by index
valueRef = msg->getHeaderValue(0);
CPPUNIT_ASSERT_MESSAGE("NULL field value", valueRef != NULL);
ASSERT_STR_EQUAL_MESSAGE("incorrect field value", value1,
valueRef);
// get header field by index and name
valueRef = msg->getHeaderValue(0, name1);
CPPUNIT_ASSERT_MESSAGE("NULL field value", valueRef != NULL);
ASSERT_STR_EQUAL_MESSAGE("incorrect field value", value1,
valueRef);
// add header field name2
msg->addHeaderField(name2, value2);
// get header field by name and index
valueRef = msg->getHeaderValue(0, name2);
CPPUNIT_ASSERT_MESSAGE("NULL field value", valueRef != NULL);
ASSERT_STR_EQUAL_MESSAGE("incorrect field value", value2,
valueRef);
// add second header field name2
msg->addHeaderField(name2, value2);
// get header field by name and index
valueRef = msg->getHeaderValue(0, name2);
CPPUNIT_ASSERT_MESSAGE("NULL field value", valueRef != NULL);
ASSERT_STR_EQUAL_MESSAGE("incorrect field value", value2,
valueRef);
// set second header field name2
msg->setHeaderValue(name2, value2b, 1);
// get header field by name and index
valueRef = msg->getHeaderValue(0, name2);
CPPUNIT_ASSERT_MESSAGE("NULL field value", valueRef != NULL);
ASSERT_STR_EQUAL_MESSAGE("incorrect field value", value2,
valueRef);
// insert header field name2 as a second header with name2
msg->insertHeaderField(name2, value2a, 2);
// get header field by name and index
valueRef = msg->getHeaderValue(0, name2);
CPPUNIT_ASSERT_MESSAGE("NULL field value", valueRef != NULL);
ASSERT_STR_EQUAL_MESSAGE("incorrect field value", value2,
valueRef);
// get overall header field count
fieldCount = msg->getCountHeaderFields();
CPPUNIT_ASSERT_EQUAL_MESSAGE("field count should be 4", 4,
fieldCount);
// get name1 header field count
fieldCount = msg->getCountHeaderFields(name1);
CPPUNIT_ASSERT_EQUAL_MESSAGE("field count should be 1", 1,
fieldCount);
// get name2 header field count
fieldCount = msg->getCountHeaderFields(name2);
CPPUNIT_ASSERT_EQUAL_MESSAGE("field count should be 3", 3,
fieldCount);
//.........这里部分代码省略.........