本文整理汇总了C++中HttpConnection::setAuthentication方法的典型用法代码示例。如果您正苦于以下问题:C++ HttpConnection::setAuthentication方法的具体用法?C++ HttpConnection::setAuthentication怎么用?C++ HttpConnection::setAuthentication使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类HttpConnection
的用法示例。
在下文中一共展示了HttpConnection::setAuthentication方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: upload
int HttpUploader::upload(const StringBuffer& luid, InputStream* inputStream)
{
int status = 0;
// safe checks
if (!inputStream || !inputStream->getTotalSize()) {
LOG.error("upload error: no data to transfer");
return 1;
}
if (luid.empty() || syncUrl.empty() || sourceURI.empty()) {
LOG.error("upload error: some params are not set");
return 2;
}
StringBuffer fullUrl = composeURL();
URL url(fullUrl.c_str());
HttpConnection* httpConnection = getHttpConnection();
httpConnection->setCompression(false);
status = httpConnection->open(url, HttpConnection::MethodPost);
if (status) {
delete httpConnection;
return status;
}
httpConnection->setKeepAlive(keepalive);
httpConnection->setRequestChunkSize(maxRequestChunkSize);
// Set headers (use basic auth)
HttpAuthentication* auth = new BasicAuthentication(username, password);
httpConnection->setAuthentication(auth);
setRequestHeaders(luid, *httpConnection, *inputStream);
// Send the HTTP request
StringOutputStream response;
status = httpConnection->request(*inputStream, response);
LOG.debug("response returned = %s", response.getString().c_str());
// Manage response headers
if (useSessionID) {
// Server returns the jsessionId in the Set-Cookie header, can be used for
// the subsequent calls of upload().
StringBuffer hdr = httpConnection->getResponseHeader(HTTP_HEADER_SET_COOKIE);
sessionID = httpConnection->parseJSessionId(hdr);
}
httpConnection->close();
delete auth;
delete httpConnection;
return status;
}