本文整理汇总了C++中CCHttpRequest::setHeaders方法的典型用法代码示例。如果您正苦于以下问题:C++ CCHttpRequest::setHeaders方法的具体用法?C++ CCHttpRequest::setHeaders怎么用?C++ CCHttpRequest::setHeaders使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CCHttpRequest
的用法示例。
在下文中一共展示了CCHttpRequest::setHeaders方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: send
void send(const char* buffer = NULL){
if(m_request != NULL){
if(NULL != buffer){
m_request->setRequestData(buffer, sizeof buffer);
}
m_request->setHeaders(m_headers);
CCHttpClient::getInstance()->send(m_request);
CC_SAFE_RELEASE_NULL(m_request);
m_headers.clear();
}
};
示例2: sendPostHttp
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();
}
示例3: onMenuPutTestClicked
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...");
}
示例4: request
/// communication
ParseError* ParseManager::request(CCHttpRequest::HttpRequestType op,
const std::string &url,
const char* buffer,
size_t size,
CCObject *receiver,
SEL_CallFuncND selector,
const char* contentType,
bool setMasterKey,
void* param)
{
ParseError* error = NULL;
CCHttpRequest* request = new CCHttpRequest();
std::vector<std::string> headers;
request->setRequestType(op);
std::string fullUrl;
if (strncmp(url.c_str(), "http", 4) != 0)
{
fullUrl = "https://api.parse.com" + url;
}
else
{
fullUrl = url;
}
request->setUrl(fullUrl.c_str());
request->setResponseCallback(receiver, selector);
request->setUserData(param);
CCHttpClient* client = CCHttpClient::getInstance();
if (contentType)
{
headers.push_back(contentType);
}
switch(op)
{
case CCHttpRequest::kHttpGet:
if (size > 0)
{
char* condition = curl_escape(buffer, size);
request->setUrl((fullUrl + "?" + condition).c_str());
}
break;
case CCHttpRequest::kHttpPost:
if (contentType == 0)
{
headers.push_back("Content-Type: application/json");
}
if (size > 0)
{
request->setRequestData(buffer, size);
}
break;
case CCHttpRequest::kHttpPut:
if (contentType == 0)
{
headers.push_back("Content-Type: application/json");
}
if (size > 0)
{
request->setRequestData(buffer, size);
}
break;
case CCHttpRequest::kHttpDelete:
break;
}
headers.push_back(std::string("X-Parse-Application-Id: ") + this->_applicationId);
if (setMasterKey)
{
headers.push_back(std::string("X-Parse-Master-Key: ") + this->_masterKey);
}
else
{
headers.push_back(std::string("X-Parse-REST-API-Key: ") + this->_apiKey);
}
request->setHeaders(headers);
client->send(request);
request->release();
return error;
}