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 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 AddFriendScene::doSearchFriend() { std::string sSearchField(m_txtSearchField->getText()); sSearchField = trimRight(sSearchField); if (sSearchField.empty()) { CCMessageBox("搜索内容不能为空","ERROR"); return; } this->ShowLoadingIndicator(""); CCHttpRequest *request = new CCHttpRequest(); request->setRequestType(CCHttpRequest::kHttpGet); request->setResponseCallback(this,httpresponse_selector(AddFriendScene::requestFinishedCallback)); request->setTag("101"); string _strUrl = CompleteUrl(URL_FRIEND_SEARCH); _strUrl.append(CCUserDefault::sharedUserDefault()->getStringForKey("userinfo")); _strUrl.append("/"); _strUrl.append(sSearchField); request->setUrl(_strUrl.c_str()); CCHttpClient *client = CCHttpClient::getInstance(); client->send(request); request->release(); }
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 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..."); }
void LoginLayer::touchUpInside(CCObject* pSender, CCControlEvent event) { // CCLog("size(%d, %d)", strlen(m_pNameBox->getText()), // strlen(m_pPasswordBox->getText())); if (strlen(m_pNameBox->getText()) > 0 && strlen(m_pPasswordBox->getText()) > 0) { string str; str.append(m_pNameBox->getText()); CCUserDefault::sharedUserDefault()->setStringForKey("UserName", m_pNameBox->getText()); CCUserDefault::sharedUserDefault()->flush(); CCDirector::sharedDirector()->replaceScene( CCTransitionFade::create(0.5, HelloWorld::scene())); } CCHttpRequest* request = new CCHttpRequest(); const char *uname = m_pNameBox->getText(); string url = "127.0.0.1:80/index.html?"; string postData = "username="******"&password="******"GetType data : %s", (url + postData).c_str()); request->setRequestType(CCHttpRequest::kHttpGet); request->setTag("GET test"); } else { request->setUrl(url.c_str()); request->setRequestType(CCHttpRequest::kHttpPost); request->setRequestData(postData.c_str(), postData.size()); CCLOG("GetType data : %s", postData.c_str()); request->setTag("POST test"); } request->setResponseCallback(this, httpresponse_selector(LoginLayer::onHttpRequestCompleted)); CCHttpClient::getInstance()->send(request); request->release(); m_pSendButton->setEnabled(false); }
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 TestLayer::btncallback( CCObject* pSender ) { bool requestType_is_get=true;//采用get方式或者post方式 if (requestType_is_get) { CCHttpRequest* request = new CCHttpRequest();//创建请求对象 string str1 = "127.0.0.1:80/index.html?"; string str2 = p_User_EditBox->getText();//获取username编辑框内容 string str3 = p_Psw_EditBox->getText();//获取password编辑框内容 string struser="******"; string strpsw="&password="******"GET test"); CCHttpClient::getInstance()->send(request);//发送请求 request->release();//释放请求 } else { CCHttpRequest* request = new CCHttpRequest();//创建请求对象 string str1 = "127.0.0.1:80/index.html"; string str2 = p_User_EditBox->getText(); string str3 = p_Psw_EditBox->getText(); string struser="******"; string strpsw="&password="******"POST test"); CCHttpClient::getInstance()->send(request);//发送请求 request->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 NetHttpReqRaw(string url,string data,string type,string tag) { CCHttpRequest* request = new CCHttpRequest(); request->setUrl(url.c_str()); request->setTag(tag.c_str()); if(type=="post"){ request->setRequestType(cocos2d::extension::CCHttpRequest::kHttpPost); request->setRequestData(data.c_str(),data.length()); }else{ request->setRequestType(cocos2d::extension::CCHttpRequest::kHttpGet); } CCHttpClient::getInstance()->send(request); }
void XMLHttpRequest::send(std::string param){ readyState = 1; CCHttpRequest *request = new CCHttpRequest(); request->setUrl(reqUrl.c_str()); request->setRequestType(CCHttpRequest::kHttpGet); // std::vector<std::string> headers; // headers.push_back("Content-Type: application/json; charset=utf-8"); // request->setHeaders(headers); request->setResponseCallback(this, callfuncND_selector(XMLHttpRequest::onHttpRequestCompleted)); request->setRequestData(param.c_str(), strlen(param.c_str())); request->setTag("wx"); CCHttpClient::getInstance()->send(request); request->release(); readyState = 3; }
void AddFriendScene::addFriendRequest(std::string &targetUser) { CCHttpRequest *request = new CCHttpRequest(); request->setRequestType(CCHttpRequest::kHttpGet); request->setResponseCallback(this,httpresponse_selector(AddFriendScene::requestFinishedCallback)); request->setTag("102"); string _strUrl = CompleteUrl(URL_FRIEND_ADD_NEW); _strUrl.append(CCUserDefault::sharedUserDefault()->getStringForKey("userinfo")); _strUrl.append("/" + targetUser); request->setUrl(_strUrl.c_str()); CCHttpClient *client = CCHttpClient::getInstance(); client->send(request); request->release(); }
void HttpClientTest::onMenuPostTestClicked(cocos2d::CCObject *sender) { CCHttpRequest* request = new CCHttpRequest(); request->setUrl("http://www.httpbin.org/post"); request->setRequestType(CCHttpRequest::kHttpPost); request->setResponseCallback(this, callfuncND_selector(HttpClientTest::onHttpRequestCompleted)); // write the post data const char* postData = "visitor=cocos2d&TestSuite=Extensions Test/NetowrkTest"; request->setRequestData(postData, strlen(postData)); request->setTag("POST test"); CCHttpClient::getInstance()->send(request); request->release(); // waiting m_labelStatusCode->setString("waiting..."); }
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..."); }
void MailMainScene::doSearchFriend() { this->ShowLoadingIndicator(""); CCHttpRequest *request = new CCHttpRequest(); request->setRequestType(CCHttpRequest::kHttpGet); request->setResponseCallback(this,callfuncND_selector(MailMainScene::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 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 GameState::sendPostHttp(CCObject* sender) { CCHttpRequest* request = new CCHttpRequest(); request->setUrl("http://deploydjango1.herokuapp.com"); request->setRequestType(CCHttpRequest::kHttpPost); std::vector<std::string> headers; headers.push_back("Content-Type: application/json; charset=utf-8"); request->setHeaders(headers); const char* postData = "text=12"; request->setRequestData(postData,strlen(postData)); request->setTag("text"); CCHttpClient::getInstance()->send(request); //보내고 나서 request->setResponseCallback(this,callfuncND_selector(GameState::onHttpRequestCompleted));//받습니다 request->release(); }
void HttpRequestTest::requestHttpInfo(CAControl* btn, CCPoint point) { loading = CAView::createWithColor(ccc4(255, 255, 255, 0)); loading->setTag(200); loading->setFrame(this->getView()->getBounds()); this->getView()->addSubview(loading); loadImage = CAImageView::createWithImage(CAImage::create("loading.png")); loadImage->setCenterOrigin(CADipPoint(size.width*0.5, size.height*0.5)); loadImage->setScale(0.5); loading->addSubview(loadImage); CAScheduler::schedule(schedule_selector(HttpRequestTest::loadingAnim), this, 0.01, false); CALabel* msg = CALabel::createWithCenter(CADipRect(size.width*0.5, size.height*0.5, loadImage->getFrame().size.width*0.9, 50)); msg->setText("Loading"); msg->setColor(CAColor_blueStyle); msg->setFontSize(_px(22)); msg->setTextAlignment(CATextAlignmentCenter); msg->setVerticalTextAlignmet(CAVerticalTextAlignmentCenter); loading->addSubview(msg); string url = ""; if (inputWebsite->getText().find("http://")==string::npos) { url = "http://" + inputWebsite->getText(); } else { url = inputWebsite->getText(); } CCHttpRequest* request = new CCHttpRequest(); request->setTag("Getpage"); request->setRequestType(CCHttpRequest::kHttpGet); request->setUrl(url.c_str()); request->setResponseCallback(this,httpresponse_selector(HttpRequestTest::requestResult)); CCHttpClient* httpClient = CCHttpClient::getInstance(); httpClient->setTimeoutForConnect(30); httpClient->send(request); request->release(); }
void HttpCenter::request(const char* pszUrl, const char* pszNotifyName, CCHttpRequest::HttpRequestType eType /* = CCHttpRequest::kHttpGet */, const char* reqData /* = NULL */) { if (!pszUrl) return; CCHttpRequest* request = new CCHttpRequest; request->setRequestType(eType); request->setUrl(pszUrl); request->setResponseCallback(this, httpresponse_selector(HttpCenter::onHttpRequestCompleted)); if (reqData) { request->setRequestData(reqData, strlen(reqData)); CCLOG("request:%s", reqData); } if (pszNotifyName) request->setTag(pszNotifyName); // Send HttpRequest CCHttpClient::getInstance()->send(request); request->release(); }
void SGHttpClient::postData(SGRequestData *data,bool isShowCon) { if ( isShowCon ) SGMainManager::shareMain()->getMainScene()->plat->showConnection(); CCHttpRequest* request = new CCHttpRequest(); request->setUrl(GlobalConfig::gi()->getAuthUrl().c_str()); request->setRequestType(CCHttpRequest::kHttpPost); request->setRequestData(data->getRequestData(), data->getRequestLength()); CCHttpClient::getInstance()->setTimeoutForConnect(20); int _tag = 0; char ctag = data->getMsgId(); memcpy(&_tag, &ctag, 1); char requestTag[1]; sprintf(requestTag, "%d",_tag); request->setTag(requestTag); request->setResponseCallback(this, callfuncND_selector(SGHttpClient::requestFinishHandler)); CCHttpClient::getInstance()->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 MenuItemImage *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 Menu* pMenu = Menu::create(closeItem, NULL); pMenu->setPosition(Point::ZERO); this->addChild(pMenu, 1); ///////////////////////////// // 3. add your codes below... // add a label shows "Hello World" // create and initialize a label LabelTTF* pLabel = LabelTTF::create("Hello World", "Arial", TITLE_FONT_SIZE); // position the label on the center of the screen pLabel->setPosition(Point(origin.x + visibleSize.width/2, origin.y + visibleSize.height - pLabel->getContentSize().height)); // add the label as a child to this layer this->addChild(pLabel, 1); // add "HelloWorld" splash screen" Sprite* pSprite = Sprite::create("HelloWorld.png"); // position the sprite on the center of the screen pSprite->setPosition(Point(visibleSize.width/2 + origin.x, visibleSize.height/2 + origin.y)); // add the sprite as a child to this layer this->addChild(pSprite, 0); // initialize flash tinyswf::SWF::initialize(CCFlashLoadAsset, 256*1024); // 256kB buffer for libtess2 tinyswf::Renderer::setInstance(new CCFlashRenderer); tinyswf::FontHandler::setInstance(new CCFlashFontHandler); CCFlash* pFlash = CCFlash::create("test.swf"); pFlash->scheduleUpdate(); this->addChild(pFlash,1); pFlash->getSWF()->get<tinyswf::Text>("_text")->setString( "<p>test<font color='#ff0000'>1234</font>hello world</p><p>font <font color='#00ffff'>color</font> test</p>"); #ifdef USE_HTTP CCHttpRequest* request = new CCHttpRequest(); request->setUrl("https://localhost/codeigniter/user/login"); request->setRequestType(CCHttpRequest::kHttpPost); request->setResponseCallback(this, httpresponse_selector(HelloWorld::onHttpRequestCompleted)); request->setTag("POST login"); std::string uuid; getUUID(uuid); std::string post = "uuid="+uuid; request->setRequestData(post.c_str(), post.length()); CCHttpClient::getInstance()->send(request); request->release(); #endif return true; }
void TartarLayer::BottonOKClicked( CCObject* pSender ) { // Check date Format is correct or not bool dateFormatIsValid = true; UITextField* pUITextField = DynamicCast<UITextField*>(UiManager::Singleton().GetChildByName("TextField_Year")); int year = atoi(pUITextField->getStringValue()); int mon = 0; int day = 0; if (year != 2013) { dateFormatIsValid = false; } if (dateFormatIsValid) { pUITextField = DynamicCast<UITextField*>(UiManager::Singleton().GetChildByName("TextField_Mon")); mon = atoi(pUITextField->getStringValue()); if (mon < 1 || mon > 12) { dateFormatIsValid = false; } } if (dateFormatIsValid) { pUITextField = DynamicCast<UITextField*>(UiManager::Singleton().GetChildByName("TextField_Day")); day = atoi(pUITextField->getStringValue()); if (day < 1 || day > 31) { dateFormatIsValid = false; } } if (!dateFormatIsValid) { UILabel* pUILabel = DynamicCast<UILabel*>(UiManager::Singleton().GetChildByName("Label_Warning")); pUILabel->setVisible(true); } else { // Get Current Date tm curTime = GetDate(); curTime.tm_hour = 0; curTime.tm_min = 0; curTime.tm_sec = 0; tm inputTime; inputTime.tm_year = year; inputTime.tm_mon = mon; inputTime.tm_mday = day; int dayDiff = GetElapseDayNum(curTime, inputTime); if (dayDiff < 0) { UILabel* pUILabel = DynamicCast<UILabel*>(UiManager::Singleton().GetChildByName("Label_Warning")); pUILabel->setVisible(true); } else { UIWidget* pUIWidget = UiManager::Singleton().GetChildByName("Panel1"); pUIWidget->setVisible(false); pUIWidget = UiManager::Singleton().GetChildByName("Panel2"); pUIWidget->setVisible(true); UILabel* pUILabelDayDiff = DynamicCast<UILabel*>(UiManager::Singleton().GetChildByName("Label_DayDiff")); char str[10]; sprintf(str,"%d",dayDiff); pUILabelDayDiff->setText(str); pUILabelDayDiff->setVisible(true); pUILabelDayDiff = DynamicCast<UILabel*>(UiManager::Singleton().GetChildByName("Label_PastDay")); pUILabelDayDiff->setVisible(true); // Request info according the diffDay. CCHttpRequest* request = new CCHttpRequest(); std::string url = "http://localhost:8000/plaque/" + std::string(str); request->setUrl(url.c_str()); request->setRequestType(CCHttpRequest::kHttpGet); request->setResponseCallback(this, httpresponse_selector(TartarLayer::onHttpRequestCompleted)); request->setTag("GET INFO"); CCHttpClient::getInstance()->send(request); request->release(); } } }
CCSprite* EziFacebookFriend::getProfilePic(cocos2d::CCLayer *sender, bool forceDownload, EziPhotoCallback callback) { _selector = callback; _target = sender; //CCLOG("Force Download = %d", forceDownload); if (_profilePic != NULL && !forceDownload) { //CCLOG("Inside IF...."); return _profilePic; } else { //CCLOG("Inside Elese...."); const char* photoKey = ""; int width = 100; int height = 100; CCString* fileName = CCString::createWithFormat("%s_%d_%d.jpg", _fbID.c_str(), width, height); photoKey = fileName->getCString(); std::string file = cocos2d::CCFileUtils::sharedFileUtils()->getWritablePath().append(photoKey); bool fileExist = cocos2d::CCFileUtils::sharedFileUtils()->isFileExist(file); if (!forceDownload && fileExist) { _profilePic = EziSocialObject::sharedObject()->generateCCSprite(photoKey); if (_profilePic == NULL) { forceDownload = true; } else { return _profilePic; } } // If we have reached here then it means we need to forcefully download the photo. const char* downloadURL = ""; //CCLOG("Photo URL = %s", this->getPhotoURL()); if (std::strcmp(_photoURL.c_str(), "") != 0) { downloadURL = _photoURL.c_str(); //CCLOG("downloadURL = %s", downloadURL); } else { //CCLOG("Creating new type of Download URL"); CCString* tempURL = CCString::createWithFormat("http://graph.facebook.com/%s/picture?width=%d&height=%d", _fbID.c_str(), 100, 100); downloadURL = tempURL->getCString(); } CCHttpRequest* request = new CCHttpRequest(); request->setUrl(downloadURL); request->setRequestType(CCHttpRequest::kHttpGet); request->setResponseCallback(this, httpresponse_selector(EziFacebookFriend::onHttpRequestCompleted)); //request->setResponseCallback(sender, httpresponse_selector(EziSocialObject::onHttpRequestCompleted)); request->setTag("ABC"); CCHttpClient::getInstance()->send(request); request->release(); } return NULL; }
void TartarLayer::onHttpRequestCompleted(CCHttpClient *sender, CCHttpResponse *response) { if (!response) { return; } int statusCode = response->getResponseCode(); char statusString[64] = {}; sprintf(statusString, "HTTP Status Code: %d, tag = %s", statusCode, response->getHttpRequest()->getTag()); CCLog("response code: %d", statusCode); if (!response->isSucceed()) { CCLog("response failed"); CCLog("error buffer: %s", response->getErrorBuffer()); return; } // dump data std::vector<char> *buffer = response->getResponseData(); std::string bufferStr(buffer->begin(),buffer->end()); if (std::string(response->getHttpRequest()->getTag()) == std::string("GET INFO")) { // Display the memberId and name. cJSON* json; json = cJSON_Parse(bufferStr.c_str()); if (json) { cJSON* messageJSON = cJSON_GetObjectItem(json, "message"); if (messageJSON) { // Set NeedCheck label UILabel* pUILabelWarning = DynamicCast<UILabel*>(UiManager::Singleton().GetChildByName("Label_NeedCheck")); pUILabelWarning->setVisible(true); pUILabelWarning->setText(messageJSON->valuestring); } cJSON* imageJSON = cJSON_GetObjectItem(json, "image"); if (imageJSON) { std::string imagePath = imageJSON->valuestring; CCHttpRequest* request = new CCHttpRequest(); std::string url = "http://localhost:8000/media/" + imagePath; request->setUrl(url.c_str()); request->setRequestType(CCHttpRequest::kHttpGet); request->setResponseCallback(this, httpresponse_selector(TartarLayer::onHttpRequestCompleted)); request->setTag("GET IMAGE"); CCHttpClient::getInstance()->send(request); request->release(); int index = imagePath.find_last_of("."); if (index != -1) { m_textureFormat = imagePath.substr(index); } } } } else { std::string path = CCFileUtils::sharedFileUtils()->getWritablePath(); // Save it locally path += "currentTeeth"; path += m_textureFormat; CCLOG("path: %s",path.c_str()); FILE *fp = fopen(path.c_str(), "wb+"); fwrite(bufferStr.c_str(), 1,buffer->size(), fp); fclose(fp); // Display UIImageView* pImage = DynamicCast<UIImageView*>(UiManager::Singleton().GetChildByName("ImageView")); pImage->setTexture(path.c_str()); CCRect rect = pImage->getRect(); float normalWidth = cocos2d::CCEGLView::sharedOpenGLView()->getDesignResolutionSize().width - 10.0f; float normalHeight = normalWidth * 0.6f; pImage->setScaleX(normalWidth / rect.size.width * pImage->getScaleX()); pImage->setScaleY(normalHeight / rect.size.height * pImage->getScaleY()); } }