本文整理汇总了C++中HttpConnection::getResponseHeader方法的典型用法代码示例。如果您正苦于以下问题:C++ HttpConnection::getResponseHeader方法的具体用法?C++ HttpConnection::getResponseHeader怎么用?C++ HttpConnection::getResponseHeader使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类HttpConnection
的用法示例。
在下文中一共展示了HttpConnection::getResponseHeader方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: httpFinished
virtual void httpFinished(HttpConnection*, int result) {
if(result == 304) { //Not Modified
printf("Program unchanged.\n");
#ifdef MA_PROF_SUPPORT_STYLUS
printf("Tap screen or press Fire to run.\n");
#else // MA_PROF_SUPPORT_STYLUS
printf("Press Fire to run.\n");
#endif // MA_PROF_SUPPORT_STYLUS
mState = eReady;
return;
}
if(result >= 200 && result <= 299) { //OK
printf("HTTP %i\n", result);
String cls;
int res = mHttp.getResponseHeader("content-length", &cls);
if(res < 0) {
printf("CL error: %i\n", res);
return;
}
int contentLength = stringToInteger(cls);
printf("Content-Length: %i\n", contentLength);
maDestroyObject(mProgram);
if(maCreateData(mProgram, contentLength) == RES_OUT_OF_MEMORY) {
printf("Out of memory!\n");
return;
}
mHttp.readToData(mProgram, 0, contentLength);
return;
} else { //error
printf("HTTP %s %i\n", (result < 0) ? "error" : "response", result);
}
}
示例2: 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;
}
示例3: processHttpResponse
// Process Response
static void processHttpResponse(HttpResponse* response, std::string& errorStr)
{
auto request = response->getHttpRequest();
long responseCode = -1;
int retValue = 0;
HttpConnection xhr;
bool ok = false;
bool manualAuthReqd = false;
// Process the request -> get response packet
switch (request->getRequestType())
{
case HttpRequest::Type::GET: // HTTP GET
ok = (xhr.init(request) && xhr.open("GET", manualAuthReqd, s_cookieFilename) && xhr.send());
break;
case HttpRequest::Type::POST: // HTTP POST
ok = (xhr.init(request) && xhr.open("POST", manualAuthReqd, s_cookieFilename) && xhr.send());
break;
case HttpRequest::Type::PUT: // HTTP PUT
ok = (xhr.init(request) && xhr.open("PUT", manualAuthReqd, s_cookieFilename) && xhr.send());
break;
case HttpRequest::Type::DELETE: // HTTP DELETE
ok = (xhr.init(request) && xhr.open("DELETE", manualAuthReqd, s_cookieFilename) && xhr.send());
break;
default:
CCASSERT(true, "CCHttpClient: unknown request type, only GET and POST are supported");
break;
}
writeData(xhr.getResponseHeader(), response->getResponseHeader());
writeData(xhr.getResponseData(), response->getResponseData());
retValue = ok ? 0 : 1;
errorStr = xhr.getErrorMessage();
responseCode = xhr.getStatusCode();
// write data to HttpResponse
response->setResponseCode(responseCode);
if (retValue != 0)
{
response->setSucceed(false);
response->setErrorBuffer(errorStr.c_str());
}
else
{
response->setSucceed(true);
}
}
示例4: connReadFinished
virtual void connReadFinished(Connection*, int result) {
if(result < 0) {
printf("Read error %i\n", result);
return;
}
//save Last-Modified header to cache
mHttp.getResponseHeader("last-modified", &mLastModified);
MAHandle data = maCreatePlaceholder();
maCreateData(data, mLastModified.length());
maWriteData(data, mLastModified.c_str(), 0, mLastModified.length());
MAHandle store = maOpenStore(MODSAV, MAS_CREATE_IF_NECESSARY);
if(store < 0) {
printf("Meta-cache open error: %i\n", store);
} else {
int res = maWriteStore(store, data);
if(res < 0) {
printf("Meta-cache write error: %i\n", res);
}
maCloseStore(store, 0);
}
maDestroyPlaceholder(data);
//save program to cache
store = maOpenStore(SAV, MAS_CREATE_IF_NECESSARY);
if(store < 0) {
printf("Cache open error: %i\n", store);
} else {
int res = maWriteStore(store, mProgram);
if(res < 0) {
printf("Cache write error: %i\n", res);
}
maCloseStore(store, 0);
}
printf("Program downloaded.\n");
#ifdef MA_PROF_SUPPORT_STYLUS
printf("Tap screen or press Fire to run.\n");
#else // MA_PROF_SUPPORT_STYLUS
printf("Press Fire to run.\n");
#endif // MA_PROF_SUPPORT_STYLUS
mState = eReady;
}