本文整理汇总了C++中FormData::appendData方法的典型用法代码示例。如果您正苦于以下问题:C++ FormData::appendData方法的具体用法?C++ FormData::appendData怎么用?C++ FormData::appendData使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类FormData
的用法示例。
在下文中一共展示了FormData::appendData方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: TestNetworkPostTransfer
/**
* Test a POST form transfer
*/
static void TestNetworkPostTransfer()
{
// FIXME Setup a http server to serve the files
TestManager::AssertTrue("No web server setup for the tests", false);
return;
const std::string aURL(TEST_WEB_SITE"testpostwithparam.php");
std::string aPath = TestManager::GetInstance().getPath() + "NetworkTests/Refs/testpostwithparam.html";
const std::string aRef(aPath);
BIResourceHandleManager* aResourceHandleManager = getBIResourceHandleManager();
TestManager::AssertTrue("Transfer Job Manager obtained", aResourceHandleManager != NULL);
std::string aFileName;
GetTemporaryUnexistingFileName("/tmp/transfer", ".txt", aFileName);
TestResourceHandleClient aTestResourceHandleClient(aFileName);
FormData formData;
DeprecatedString aParams;
aParams = "param1=toto¶m2=kiki";
formData.appendData( static_cast<const void *> (aParams.ascii()), aParams.length() );
ResourceRequest aResourceRequest = ResourceRequest(static_cast<const KURL&> (aURL.c_str()));
aResourceRequest.setHTTPMethod("POST");
aResourceRequest.setHTTPReferrer(TEST_WEB_SITE);
aResourceRequest.setHTTPBody(formData.copy());;
RefPtr<BIResourceHandle> aResourceHandle = BIResourceHandle::create(aResourceRequest, &aTestResourceHandleClient, 0, false, false, false);
TestManager::AssertTrue("FormData flatten", aResourceRequest.httpBody()->flattenToString() == "param1=toto¶m2=kiki" );
TestManager::AssertTrue("Form data with correct element", aResourceRequest.httpBody()->elements().size() == 1 );
TestManager::AssertTrue("Correct Metadata", aResourceRequest.httpReferrer() == TEST_WEB_SITE );
TestManager::AssertTrue("Correct Method", aResourceHandle->method() == "POST");
gTransferFileCount = 1;
// Wait for the end of the transfer.
gTimeout = false;
WebCore::Timer<NetworkTest> aTimeoutTimer(NULL,&NetworkTest::TimeoutCallback);
aTimeoutTimer.startOneShot(20); // timeout in 20s
BIEventLoop* aEventLoop = BAL::getBIEventLoop();
BIEvent* event;
while( gTransferFileCount && !gTimeout ) {
aEventLoop->WaitEvent(event);
}
TestManager::AssertTrue("Transfer done", !gTransferFileCount );
BALFileComparison aFileComparison;
bool bEqual = aFileComparison.AreEqual( aFileName, aRef );
TestManager::AssertTrue("File as expected", bEqual );
unlink( aFileName.c_str() );
}
示例2: formData
bool HTMLFormElement::formData(FormData &form_data) const
{
DeprecatedCString enc_string = ""; // used for non-multipart data
DeprecatedString str = m_acceptcharset.deprecatedString();
str.replace(',', ' ');
DeprecatedStringList charsets = DeprecatedStringList::split(' ', str);
TextEncoding encoding(InvalidEncoding);
Frame *frame = document()->frame();
for (DeprecatedStringList::Iterator it = charsets.begin(); it != charsets.end(); ++it) {
if ((encoding = TextEncoding((*it).latin1())).isValid())
break;
}
if (!encoding.isValid()) {
if (frame)
encoding = TextEncoding(frame->encoding().latin1());
else
encoding = TextEncoding(Latin1Encoding);
}
for (unsigned i = 0; i < formElements.size(); ++i) {
HTMLGenericFormElement* current = formElements[i];
FormDataList lst(encoding);
if (!current->disabled() && current->appendFormData(lst, m_multipart)) {
for (DeprecatedValueListConstIterator<FormDataListItem> it = lst.begin(); it != lst.end(); ++it) {
if (!m_multipart) {
// handle ISINDEX / <input name=isindex> special
// but only if its the first entry
if ( enc_string.isEmpty() && (*it).m_data == "isindex" ) {
++it;
enc_string += encodeCString( (*it).m_data );
}
else {
if(!enc_string.isEmpty())
enc_string += '&';
enc_string += encodeCString((*it).m_data);
enc_string += "=";
++it;
enc_string += encodeCString((*it).m_data);
}
}
else
{
DeprecatedCString hstr("--");
hstr += m_boundary.deprecatedString().latin1();
hstr += "\r\n";
hstr += "Content-Disposition: form-data; name=\"";
hstr += (*it).m_data.data();
hstr += "\"";
// if the current type is FILE, then we also need to
// include the filename
if (current->hasLocalName(inputTag) &&
static_cast<HTMLInputElement*>(current)->inputType() == HTMLInputElement::FILE) {
DeprecatedString path = static_cast<HTMLInputElement*>(current)->value().deprecatedString();
// FIXME: This won't work if the filename includes a " mark,
// or control characters like CR or LF. This also does strange
// things if the filename includes characters you can't encode
// in the website's character set.
hstr += "; filename=\"";
hstr += encoding.fromUnicode(path.mid(path.findRev('/') + 1), true);
hstr += "\"";
if (!static_cast<HTMLInputElement*>(current)->value().isEmpty()) {
DeprecatedString mimeType = frame ? frame->mimeTypeForFileName(path).deprecatedString() : DeprecatedString();
if (!mimeType.isEmpty()) {
hstr += "\r\nContent-Type: ";
hstr += mimeType.ascii();
}
}
}
hstr += "\r\n\r\n";
++it;
// append body
form_data.appendData(hstr.data(), hstr.length());
const FormDataListItem &item = *it;
size_t dataSize = item.m_data.size();
if (dataSize != 0)
form_data.appendData(item.m_data, dataSize - 1);
else if (!item.m_path.isEmpty())
form_data.appendFile(item.m_path);
form_data.appendData("\r\n", 2);
}
}
}
}
if (m_multipart)
enc_string = ("--" + m_boundary.deprecatedString() + "--\r\n").ascii();
form_data.appendData(enc_string.data(), enc_string.length());
return true;
}