void HttpClientTest::onMenuDeleteTestClicked(CCObject *sender) { // test 1 { CCHttpRequest* request = new CCHttpRequest(); request->setUrl("http://just-make-this-request-failed.com"); request->setRequestType(CCHttpRequest::kHttpDelete); request->setResponseCallback(this, httpresponse_selector(HttpClientTest::onHttpRequestCompleted)); request->setTag("DELETE test1"); CCHttpClient::getInstance()->send(request); request->release(); } // test 2 { CCHttpRequest* request = new CCHttpRequest(); request->setUrl("http://httpbin.org/delete"); request->setRequestType(CCHttpRequest::kHttpDelete); request->setResponseCallback(this, httpresponse_selector(HttpClientTest::onHttpRequestCompleted)); request->setTag("DELETE test2"); CCHttpClient::getInstance()->send(request); request->release(); } // waiting m_labelStatusCode->setString("waiting..."); }
void EziSocialObject::downloadPhoto(CCLayer* parentNode, const char *fbID, const char *fbURL, const char* filename, bool forceDownloadFromServer) { if (forceDownloadFromServer == false) // Check if local copy exist { std::string file = cocos2d::CCFileUtils::sharedFileUtils()->getWritablePath().append(filename); bool fileExist = cocos2d::CCFileUtils::sharedFileUtils()->isFileExist(file); if (fileExist) { internalUserPhotoCallback(file.c_str(), fbID); return; } } // If we have reached here; that means local copy does not exsist. Download a new one. CCHttpRequest* request = new CCHttpRequest(); request->setUrl(fbURL); request->setRequestType(CCHttpRequest::kHttpGet); request->setResponseCallback(parentNode, httpresponse_selector(EziSocialObject::onHttpRequestCompleted)); request->setTag(filename); CCHttpClient::getInstance()->send(request); request->release(); }
void QimiAlipayView::rechargeOnClick(cocos2d::CCNode* pSender, cocos2d::extension::CCControlEvent* pCCControlEvent) { m_money = atoi(m_pEditName->getText()); CCHttpRequest* request = new CCHttpRequest(); request->setUrl("http://www.qimi.com/platform/addOrder.php"); request->setRequestType(CCHttpRequest::kHttpPost); request->setResponseCallback(this, httpresponse_selector(QimiAlipayView::onLoadOrderSucssful)); char sign[255]; sprintf(sign, "%s%d%s", m_uId.c_str(), m_sId, m_key.c_str()); QimiMD5 md5; md5.update(sign); CCLog("md5str==%s",sign); std::string md5tolower = md5.toString(); CCString* postDataStr = CCString::createWithFormat("uId=%s&sId=%d&sign=%s&money=%d&orderType=alipay&type=0", m_uId.c_str(), m_sId, md5tolower.c_str(), m_money); CCLog("addOrder string ===%s", postDataStr->getCString()); const char* postData =postDataStr->getCString(); request->setRequestData(postData, strlen(postData)); request->setTag("POST test1"); CCHttpClient::getInstance()->send(request); request->release(); RequestLoadingView* mask = RequestLoadingView::create(); mask->setTag(100000); this->addChild(mask); }
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(); } }
void RequestTopaz::ProfileTimer(float f) { // 프로필 사진 왼쪽 위 지점과 스크롤뷰 위치를 비교한다. // 음수가 되면, 아래에 있던 프로필이 스크롤뷰에 보이기 시작했다는 의미 -> 프로필 로딩 시작. CCPoint p; float h; int numOfList = friendList.size(); for (int i = 0 ; i < friendList.size() ; i++) { ProfileSprite* psp = ProfileSprite::GetObj(friendList[i]->GetImageUrl()); if (psp->IsLoadingStarted() || psp->IsLoadingDone()) continue; if (spriteClassScroll == NULL) return; p = ((CCSprite*)spriteClassScroll->FindSpriteByTag(-888*(numOfList-i)))->convertToNodeSpace(scrollView->getPosition()); h = friendList[i]->GetProfile()->getContentSize().height; if (p.y - h < 0) { psp->SetLoadingStarted(true); char tag[6]; CCHttpRequest* req = new CCHttpRequest(); req->setUrl(psp->GetProfileUrl().c_str()); req->setRequestType(CCHttpRequest::kHttpPost); req->setResponseCallback(this, httpresponse_selector(RequestTopaz::onHttpRequestCompletedNoEncrypt)); sprintf(tag, "%d", i); req->setTag(tag); CCHttpClient::getInstance()->send(req); req->release(); } } }
void EmailService::getEmailConfigurations(App42CallBack* pTarget, SEL_App42CallFuncND pSelector) { App42EmailResponse *response = new App42EmailResponse::App42EmailResponse(pTarget,pSelector); try { Util::throwExceptionIfTargetIsNull(pTarget, "Callback's Target"); Util::throwExceptionIfCallBackIsNull(pSelector, "Callback"); } catch (App42Exception *e) { std::string ex = e->what(); response->httpErrorCode = e->getHttpErrorCode(); response->appErrorCode = e->getAppErrorCode(); response->errorDetails = ex; response->isSuccess = false; if (pTarget && pSelector) { (pTarget->*pSelector)((App42CallBack *)pTarget, response); } delete e; e = NULL; return; } string timestamp = Util::getTimeStamp(); /** * Creating SignParams and signature */ map<string, string> signParams; populateSignParams(signParams); string signature = Util::signMap(secretKey, signParams); /** * Creating URL */ string resource = "email"; resource.append("/configuration"); string baseUrl = getBaseUrl(resource); baseUrl.append("?"); string encodedUrl = url_encode(baseUrl); // Util::app42Trace("\n baseUrl = %s",baseUrl.c_str()); // Util::app42Trace("\n createUserbody = %s",createUserbody.c_str()); /** * Creating Headers */ std::vector<std::string> headers; map<string, string> metaHeaders; populateMetaHeaderParams(metaHeaders); Util::BuildHeaders(metaHeaders, headers); Util::BuildHeaders(apiKey, timestamp, VERSION, signature, headers); /** * Initiating Http call */ Util::executeGet(encodedUrl, headers, response, httpresponse_selector(App42UserResponse::onComplete)); }
// Handle for CCHttpRequest with optional function LuaEventHandler * handle(CCHttpRequest *req, int handler = 0){ if(req){ if(handler > 0){ handle(handler);} req->setResponseCallback(this, httpresponse_selector(LuaEventHandler::onHttpResponse)); CCHttpClient::getInstance()->send(req); req->release(); } return this; }
void HttpClientTest::onMenuGetTestClicked(cocos2d::CCObject *sender) { // test 1 { CCHttpRequest* request = new CCHttpRequest(); request->setUrl("http://just-make-this-request-failed.com"); request->setRequestType(CCHttpRequest::kHttpGet); request->setResponseCallback(this, httpresponse_selector(HttpClientTest::onHttpRequestCompleted)); request->setTag("GET test1"); CCHttpClient::getInstance()->send(request); request->release(); } // test 2 { CCHttpRequest* request = new CCHttpRequest(); // required fields request->setUrl("http://httpbin.org/ip"); request->setRequestType(CCHttpRequest::kHttpGet); request->setResponseCallback(this, httpresponse_selector(HttpClientTest::onHttpRequestCompleted)); // optional fields request->setTag("GET test2"); CCHttpClient::getInstance()->send(request); // don't forget to release it, pair to new request->release(); } // test 3 { CCHttpRequest* request = new CCHttpRequest(); request->setUrl("http://httpbin.org/get"); request->setRequestType(CCHttpRequest::kHttpGet); request->setResponseCallback(this, httpresponse_selector(HttpClientTest::onHttpRequestCompleted)); request->setTag("GET test3"); CCHttpClient::getInstance()->send(request); request->release(); } // waiting m_labelStatusCode->setString("waiting..."); }
bool FFHttpClient::init() { mHttpRequest = new CCHttpRequest(); mHttpRequest->setRequestType(CCHttpRequest::kHttpGet); mHttpRequest->setUrl("http://www.baidu.com"); mHttpRequest->setResponseCallback(this, httpresponse_selector(FFHttpClient::didGetResponse)); mHttpRequest->setTag("FFHttpClient"); return true; }
void YHHttpClient::sendData(YHByteArray * bytes, CCHttpRequest::HttpRequestType type) { CCHttpRequest * request = new CCHttpRequest(); request->setRequestType(type); request->setUrl(m_url.c_str()); request->setRequestData((const char *)bytes->getBuffer(), bytes->readableBytes()); request->setResponseCallback(this, httpresponse_selector(YHHttpClient::onResponseCallBack)); m_httpClient->send(request); request->release(); }
// on "init" you need to initialize your instance bool HelloWorld::init() { ////////////////////////////// // 1. super init first if ( !Layer::init() ) { return false; } Size visibleSize = Director::getInstance()->getVisibleSize(); Point origin = Director::getInstance()->getVisibleOrigin(); ///////////////////////////// // 2. add a menu item with "X" image, which is clicked to quit the program // you may modify it. // add a "close" icon to exit the progress. it's an autorelease object auto closeItem = MenuItemImage::create( "CloseNormal.png", "CloseSelected.png", CC_CALLBACK_1(HelloWorld::menuCloseCallback, this)); closeItem->setPosition(Point(origin.x + visibleSize.width - closeItem->getContentSize().width/2 , origin.y + closeItem->getContentSize().height/2)); // create menu, it's an autorelease object auto menu = Menu::create(closeItem, NULL); menu->setPosition(Point::ZERO); this->addChild(menu, 1); ///////////////////////////// // 3. add your codes below... // add a label shows "Hello World" // create and initialize a label auto label = LabelTTF::create("Hello World", "Arial", 24); // position the label on the center of the screen label->setPosition(Point(origin.x + visibleSize.width/2, origin.y + visibleSize.height - label->getContentSize().height)); // add the label as a child to this layer this->addChild(label, 1); auto request = new extension::HttpRequest(); request->setUrl("http://befool.co.jp/images/logo_befool.jpg"); request->setRequestType(extension::HttpRequest::Type::GET); request->setResponseCallback(this, httpresponse_selector(HelloWorld::onHttpRequestCompleted)); extension::HttpClient::getInstance()->send(request); return true; }
void LoginLayer::BottonOKClicked( CCObject* pSender ) { CCHttpRequest* request = new CCHttpRequest(); std::string url = "http://127.0.0.1:8000/member/" + std::string(m_pTextField->getString()); request->setUrl(url.c_str()); request->setRequestType(CCHttpRequest::kHttpGet); request->setResponseCallback(this, httpresponse_selector(LoginLayer::onHttpRequestCompleted)); request->setTag("GET test1"); CCHttpClient::getInstance()->send(request); request->release(); }
void CDownloadPackage::requestVersionInfo() { std::string sUpdateServer = CCUserDefault::sharedUserDefault()->getStringForKey(SERVER_FOR_UPDATE); CCString* pUrl = CCString::createWithFormat("%s%s?r=%ld", sUpdateServer.c_str(), PACKAGE_VERSION_FILE, getCurrentTime()); CCHttpRequest* request = new CCHttpRequest(); request->setUrl(pUrl->getCString()); request->setRequestType(CCHttpRequest::kHttpGet); request->setResponseCallback(this, httpresponse_selector(CDownloadPackage::requestVersionInfoCallBack)); CCHttpClient::getInstance()->send(request); request->release(); }
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(); } } }
void HttpClientTest::onMenuPutTestClicked(CCObject *sender) { // test 1 { CCHttpRequest* request = new CCHttpRequest(); request->setUrl("http://httpbin.org/put"); request->setRequestType(CCHttpRequest::kHttpPut); request->setResponseCallback(this, httpresponse_selector(HttpClientTest::onHttpRequestCompleted)); // write the post data const char* postData = "visitor=cocos2d&TestSuite=Extensions Test/NetworkTest"; request->setRequestData(postData, strlen(postData)); request->setTag("PUT test1"); CCHttpClient::getInstance()->send(request); request->release(); } // test 2: set Content-Type { CCHttpRequest* request = new CCHttpRequest(); request->setUrl("http://httpbin.org/put"); request->setRequestType(CCHttpRequest::kHttpPut); std::vector<std::string> headers; headers.push_back("Content-Type: application/json; charset=utf-8"); request->setHeaders(headers); request->setResponseCallback(this, httpresponse_selector(HttpClientTest::onHttpRequestCompleted)); // write the post data const char* postData = "visitor=cocos2d&TestSuite=Extensions Test/NetworkTest"; request->setRequestData(postData, strlen(postData)); request->setTag("PUT test2"); CCHttpClient::getInstance()->send(request); request->release(); } // waiting m_labelStatusCode->setString("waiting..."); }
void RewardService::CreateReward(string rewardName,string description, App42CallBack* pTarget, SEL_App42CallFuncND pSelector) { App42RewardResponse *response = new App42RewardResponse::App42RewardResponse(pTarget,pSelector); try { Util::throwExceptionIfStringNullOrBlank(description, "Description"); Util::throwExceptionIfStringNullOrBlank(rewardName, "Reward Name"); Util::throwExceptionIfTargetIsNull(pTarget, "Callback's Target"); Util::throwExceptionIfCallBackIsNull(pSelector, "Callback"); } catch (App42Exception *e) { std::string ex = e->what(); response->httpErrorCode = e->getHttpErrorCode(); response->appErrorCode = e->getAppErrorCode(); response->errorDetails = ex; response->isSuccess = false; if (pTarget && pSelector) { (pTarget->*pSelector)((App42CallBack *)pTarget, response); } delete e; e = NULL; return; } map<string, string> postMap; populateSignParams(postMap); string rewardbody = BuildCreateRewardBody(rewardName, description); postMap["body"] = rewardbody; string signature = Util::signMap(secretKey, postMap); string baseUrl = getBaseUrl("game/reward"); baseUrl.append("?"); //Util::app42Trace("\n baseUrl = %s",baseUrl.c_str()); //Util::app42Trace("\n createRewardbody = %s",rewardbody.c_str()); std::vector<std::string> headers; map<string, string> metaHeaders; populateMetaHeaderParams(metaHeaders); Util::BuildHeaders(metaHeaders, headers); string timestamp = Util::getTimeStamp(); Util::BuildHeaders(apiKey, timestamp, VERSION, signature, headers); Util::executePost(baseUrl, headers, rewardbody.c_str(), response, httpresponse_selector(App42RewardResponse::onComplete)); }
void RewardService::GetGameRewardPointsForUser(string gameName, string userName, App42CallBack* pTarget, SEL_App42CallFuncND pSelector) { App42RewardResponse *response = new App42RewardResponse::App42RewardResponse(pTarget,pSelector); try { Util::throwExceptionIfStringNullOrBlank(gameName, "Game Name"); Util::throwExceptionIfStringNullOrBlank(userName, "User Name"); Util::throwExceptionIfTargetIsNull(pTarget, "Callback's Target"); Util::throwExceptionIfCallBackIsNull(pSelector, "Callback"); } catch (App42Exception *e) { std::string ex = e->what(); response->httpErrorCode = e->getHttpErrorCode(); response->appErrorCode = e->getAppErrorCode(); response->errorDetails = ex; response->isSuccess = false; if (pTarget && pSelector) { (pTarget->*pSelector)((App42CallBack *)pTarget, response); } delete e; e = NULL; return; } string resource = "game/reward/"; resource.append(gameName+"/"); resource.append(userName); string url = getBaseUrl(resource); string timestamp = Util::getTimeStamp(); map<string, string> getMap; Util::BuildGetSigningMap(apiKey, timestamp, VERSION, getMap); getMap["gameName"] = gameName; getMap["userName"] = userName; string signature = Util::signMap(secretKey, getMap); url.append("?"); //Util::app42Trace("\n baseUrl = %s",url.c_str()); std::vector<std::string> headers; map<string, string> metaHeaders; populateMetaHeaderParams(metaHeaders); Util::BuildHeaders(metaHeaders, headers); Util::BuildHeaders(apiKey, timestamp, VERSION, signature, headers); Util::executeGet(url,headers, response, httpresponse_selector(App42RewardResponse::onComplete)); }
void ScoreService::AddScore(string gameName, string userName, double score, Object* pTarget, cocos2d::SEL_CallFuncND pSelector) { App42GameResponse *response = new App42GameResponse::App42GameResponse(pTarget,pSelector); try { Util::throwExceptionIfStringNullOrBlank(gameName, "Game Name"); Util::throwExceptionIfStringNullOrBlank(userName, "User Name"); Util::throwExceptionIfTargetIsNull(pTarget, "Callback's Target"); Util::throwExceptionIfCallBackIsNull(pSelector, "Callback"); } catch (App42Exception *e) { std::string ex = e->what(); response->httpErrorCode = e->getHttpErrorCode(); response->appErrorCode = e->getAppErrorCode(); response->errorDetails = ex; response->isSuccess = false; if (pTarget && pSelector) { (pTarget->*pSelector)((cocos2d::Node *)pTarget, response); } delete e; e = NULL; return; } map<string, string> postMap; populateSignParams(postMap); string addScoreBody = BuildScoreBody(gameName, userName,score); postMap["body"] = addScoreBody; string signature = Util::signMap(secretKey, postMap); string baseUrl = getBaseUrl("game/score/add"); baseUrl.append("?"); //Util::app42Trace("\n baseUrl = %s",baseUrl.c_str()); //Util::app42Trace("\n addScoreBody = %s",addScoreBody.c_str()); std::vector<std::string> headers; map<string, string> metaHeaders; populateMetaHeaderParams(metaHeaders); Util::BuildHeaders(metaHeaders, headers); string timestamp = Util::getTimeStamp(); Util::BuildHeaders(apiKey, timestamp, VERSION, signature, headers); Util::executePost(baseUrl, headers, addScoreBody.c_str(), response, httpresponse_selector(App42GameResponse::onComplete)); }
HttpRequest* getHttpReq(const char* url, const char* tag, HttpRequest::Type type /*= HttpRequest::Type::POST*/, bool supportJson/* = false*/) { HttpRequest* request = new HttpRequest(); request->setUrl(url); request->setRequestType(type); request->setTag(tag); if(supportJson){ std::vector<std::string> headers; headers.push_back("Content-Type: application/json; charset=utf-8"); request->setHeaders(headers); } HttpCallback* http_callback = new HttpCallback(); request->setResponseCallback(http_callback, httpresponse_selector(HttpCallback::callbackReg)); _httpMap[tag] = http_callback; return request; }
void CommandManager::doSend(Command* command) { m_currentCommand = command; CCHttpRequest* request = new CCHttpRequest(); request->setRequestType(CCHttpRequest::kHttpPost); request->setUrl(Command::URL.c_str()); const vector<char>& data = command->getData(); request->setRequestData(&data[0], data.size()); request->setResponseCallback(this, httpresponse_selector(CommandManager::onResponse)); CCHttpClient::getInstance()->send(request); }
void Army::onEnter() { LayerWithDialog::onEnter(); this->setTouchEnabled(true); char url[255]; std::string server = STATIC_DATA_STRING("server"); sprintf(url, "%sarms/infoApi&SID=%s", server.c_str(), Load::sharedSessionId.c_str()); request->setUrl(url); request->setRequestType(CCHttpRequest::kHttpGet); request->setResponseCallback(this, httpresponse_selector(Army::onInfoRequestCompleted)); request->setTag("arms"); cocos2d::extension::CCHttpClient::getInstance()->send(request); request->release(); }
void JSHttpRequest::call( std::string url, std::string params, std::string tag ) { this->mUrl = url; this->mParams = params; this->mTag = tag; m_Request = new CCHttpRequest( ); m_Request->setUrl( url.c_str( ) ); m_Request->setRequestType( (CCHttpRequest::HttpRequestType)mRequestType ); // write the post data m_Request->setRequestData( params.c_str( ), strlen( params.c_str( ) ) ); m_Request->setResponseCallback( this, httpresponse_selector(JSHttpRequest::onHttpData) ); m_Request->setTag( tag.c_str( ) ); CCHttpClient::getInstance( )->send( m_Request ); CCLog( "[JSHttpRequest] send:%s", params.c_str( ) ); m_Request->release( ); }
/** * 开始加载 */ void CXXUrlRequest::go() { for (FILECALLBACKS_ITER iter = fileCallbacks.begin(); iter != fileCallbacks.end(); ++iter) { HttpRequest* request = new HttpRequest(); std::string filePath = this->url + iter->first; request->setUrl(filePath.c_str()); request->setRequestType(HttpRequest::Type::GET); request->setResponseCallback(this, httpresponse_selector(CXXUrlRequest::onHttpRequestCompleted)); request->setTag(iter->first.c_str()); // HttpClient::getInstance()->setTimeoutForRead(2); HttpClient::getInstance()->send(request); request->release(); // log("请求文件%s",filePath.c_str()); } }
void CKHttpUtils::getText(const char* url,std::function<void(CKHttpModel* model)> callback) { #if (CC_TARGET_PLATFORM != CC_PLATFORM_WP8) CKNetStruct* sInfo = new CKNetStruct("getTextName",callback); sInfo->showLoadingDialog(); HttpRequest* request = new HttpRequest(); request->setUrl(url); request->setRequestType(HttpRequest::Type::GET); request->setResponseCallback(this, httpresponse_selector(CKHttpUtils::onGetTextCompleted)); request->setTag("getText"); request->setUserData(sInfo); HttpClient::getInstance()->send(request); request->release(); #endif }
void HttpClientTest::onMenuPostBinaryTestClicked(cocos2d::CCObject *sender) { CCHttpRequest* request = new CCHttpRequest(); request->setUrl("http://httpbin.org/post"); request->setRequestType(CCHttpRequest::kHttpPost); request->setResponseCallback(this, httpresponse_selector(HttpClientTest::onHttpRequestCompleted)); // write the post data char postData[22] = "binary=hello\0\0cocos2d"; // including \0, the strings after \0 should not be cut in response request->setRequestData(postData, 22); request->setTag("POST Binary test"); CCHttpClient::getInstance()->send(request); request->release(); // waiting m_labelStatusCode->setString("waiting..."); }
bool Net::httpRequest(std::string & url, int cbFunc) { HttpRequest* request = new HttpRequest(); request->setUrl(url.c_str()); request->setRequestType(HttpRequest::Type::GET); request->setResponseCallback(this, httpresponse_selector(Net::httpResponse)); char buf[16] = {0}; sprintf(buf, "%x", cbFunc); std::string tag(buf); request->setTag(tag.c_str()); requestMap[tag] = cbFunc; HttpClient::getInstance()->send(request); request->release(); return true; }
bool LoadingImagetNode::init() { if(!Node::init()) { return false; } HttpRequest* m_pRequest = new HttpRequest(); m_pRequest->setUrl(m_sUrlImage); m_pRequest->setRequestType(HttpRequest::Type::GET); m_pRequest->setTag("UserInfo"); m_pRequest->setResponseCallback(this, httpresponse_selector(LoadingImagetNode::onHttpRequestCompleted)); HttpClient::getInstance()->send(m_pRequest); m_pRequest->release(); m_pRequest = NULL; return true; }
void MDHeroPrePromoLayer::showTaskInfo() { this->ShowLoadingIndicator(""); CCHttpRequest *request = new CCHttpRequest(); request->setRequestType(CCHttpRequest::kHttpGet); request->setResponseCallback(this,httpresponse_selector(MDHeroPrePromoLayer::requestFinishedCallback)); request->setTag("101"); string _strUrl = CompleteUrl(URL_FRIEND_LIST); _strUrl.append(CCUserDefault::sharedUserDefault()->getStringForKey("userinfo")); request->setUrl(_strUrl.c_str()); CCHttpClient *client = CCHttpClient::getInstance(); client->send(request); request->release(); }
void SIOClientImpl::handshake() { log("SIOClientImpl::handshake() called"); std::stringstream pre; pre << "http://" << _uri << "/socket.io/1"; HttpRequest* request = new HttpRequest(); request->setUrl(pre.str().c_str()); request->setRequestType(HttpRequest::kHttpGet); request->setResponseCallback(this, httpresponse_selector(SIOClientImpl::handshakeResponse)); request->setTag("handshake"); log("SIOClientImpl::handshake() waiting"); HttpClient::getInstance()->send(request); request->release(); return; }
void UploadData::upload(TYPE type) { std::string url; mType = type; initUrl(url); //大厅136以上 if (DeviceData::getInstance()->getGloudVersionNameInteger() > GLOUD_GAME_VERSION + 1 && url.length() > 0) { network::HttpRequest* request = new (std::nothrow) network::HttpRequest(); log("UploadData 正在上传 ===> %s", url.c_str()); request->setUrl(url.c_str()); request->setRequestData(nullptr, 0); request->setRequestType(network::HttpRequest::Type::GET); request->setResponseCallback(this, httpresponse_selector(UploadData::onHttpRequestCompleted)); network::HttpClient * client = network::HttpClient::getInstance(); client->setTimeoutForConnect(2); client->setTimeoutForRead(2); client->sendImmediate(request); request->release(); } }