コード例 #1
0
ファイル: CommonHttpManager.cpp プロジェクト: WoYang/CrossApp
void CommonHttpManager::send_postFile(const std::string& url,std::map<std::string, std::string> key_value,const std::string& file,CAObject* pTarget,SEL_CommonHttpJson pSelector,bool isLoading)
{
    std::string postData;
    if (!key_value.empty())
    {
        std::map<std::string, std::string>::iterator itr = key_value.begin();
        
        do
        {
            postData = postData + itr->first + "=" + itr->second;
            itr++;
            CC_BREAK_IF(itr==key_value.end());
            postData = postData + "&";
        }
        while (1);
    }
    
    CAHttpRequest* httpRequest = new CAHttpRequest();
    httpRequest->setUrl(url.c_str());
    httpRequest->setRequestType(CAHttpRequest::kHttpPostFile);
    httpRequest->setRequestData(postData.c_str(), postData.length());
    httpRequest->setFileNameToPost(file);
    CommonHttpResponseCallBack* callBack = CommonHttpResponseCallBack::create(pTarget, pSelector, url, CommonHttpResponseCallBack::CommonHttpResponseJsonNoCache);
    httpRequest->setResponseCallback(callBack, httpresponse_selector(CommonHttpResponseCallBack::onResponse));
    
    std::sort(m_pHttpJsonClients.begin(), m_pHttpJsonClients.end(), compareHttpClient);
    m_pHttpJsonClients.front()->send(httpRequest);
    httpRequest->release();
    
    if (isLoading)
    {
        this->starActivityIndicatorView();
    }
    
}
コード例 #2
0
void CommonHttpManager::get_image(const std::string& url,
                                                         CAObject* pTarget,
                                                         SEL_CommonHttpImage pSelector,
                                                         const HttpGetImageType& type)
{
    std::string key = MD5(url).md5();
    
    CAImage* image = CAImageCache::sharedImageCache()->imageForKey(key);
    CommonHttpResponseCallBack* callBack = NULL;
    
    if (image)
    {
        (pTarget->*pSelector)(image, url.c_str());
    }
    else if (_httpResponses.count(url) > 0)
    {
        callBack = CommonHttpResponseCallBack::scheduleCallBack(pTarget, pSelector, url);
    }
    else
    {
        std::string imagePath = CCFileUtils::sharedFileUtils()->getWritablePath() + "image/" + key;
        
        unsigned long pSize = 0;
        
        FILE* fp = fopen(imagePath.c_str(), "rb");
        if (fp)
        {
            fseek(fp, 0L, SEEK_END);
            pSize = ftell(fp);
            fseek(fp,0,SEEK_SET);
            fclose(fp);
        }
        
        if (pSize > 1)
        {
            callBack = CommonHttpResponseCallBack::imagePathAsync(pTarget, pSelector, imagePath, url, type);
        }
        else
        {
            CAHttpRequest* httpRequest = new CAHttpRequest();
            httpRequest->setUrl(url.c_str());
            httpRequest->setRequestType(CAHttpRequest::kHttpGet);
            std::vector<std::string> header;
            //header.push_back("Referer:");
            httpRequest->setHeaders(header);
            callBack = CommonHttpResponseCallBack::create(pTarget, pSelector, url, type);
            httpRequest->setResponseCallback(callBack, httpresponse_selector(CommonHttpResponseCallBack::onResponse));
            
            std::sort(m_pHttpImageClients.begin(), m_pHttpImageClients.end(), compareHttpClient);
            m_pHttpImageClients.front()->send(httpRequest);
            httpRequest->release();
        }
    }
}
コード例 #3
0
void CommonHttpManager::send_get(const std::string& url,std::map<std::string,
                                 std::string> key_value,
                                 CAObject* pTarget,
                                 SEL_CommonHttpJson pSelector,
                                 bool isLoading)
{
    std::string getRul = url;
    if (!key_value.empty())
    {
        getRul += "?";
        
        std::map<std::string, std::string>::iterator itr = key_value.begin();
        
        do
        {
            getRul = getRul + itr->first + "=" + itr->second;
            itr++;
            CC_BREAK_IF(itr==key_value.end());
            getRul = getRul + "&";
        }
        while (1);
    }

    CAHttpRequest* httpRequest = new CAHttpRequest();
    httpRequest->setUrl(getRul.c_str());
    httpRequest->setRequestType(CAHttpRequest::kHttpGet);
    CommonHttpResponseCallBack* callBack = CommonHttpResponseCallBack::create(pTarget, pSelector, url, CommonHttpResponseCallBack::CommonHttpResponseJson);
    httpRequest->setResponseCallback(callBack, httpresponse_selector(CommonHttpResponseCallBack::onResponse));
    
    std::sort(m_pHttpJsonClients.begin(), m_pHttpJsonClients.end(), compareHttpClient);
    m_pHttpJsonClients.front()->send(httpRequest);
    httpRequest->release();
    
    if (isLoading)
    {
        this->starActivityIndicatorView();
    }
}