Update samples/TestCpp/Classes/ExtensionsTest/NetworkTest/HttpClientTest.cpp

Added test to show use of HttpRequest::setHeaders
This commit is contained in:
ncrothe 2012-09-24 12:15:53 +03:00
parent b3f5a04ad4
commit e0fe233752
1 changed files with 33 additions and 11 deletions

View File

@ -100,6 +100,8 @@ void HttpClientTest::onMenuGetTestClicked(cocos2d::CCObject *sender)
}
void HttpClientTest::onMenuPostTestClicked(cocos2d::CCObject *sender)
{
// test 1
{
CCHttpRequest* request = new CCHttpRequest();
request->setUrl("http://www.httpbin.org/post");
@ -107,12 +109,32 @@ void HttpClientTest::onMenuPostTestClicked(cocos2d::CCObject *sender)
request->setResponseCallback(this, callfuncND_selector(HttpClientTest::onHttpRequestCompleted));
// write the post data
const char* postData = "visitor=cocos2d&TestSuite=Extensions Test/NetowrkTest";
const char* postData = "visitor=cocos2d&TestSuite=Extensions Test/NetworkTest";
request->setRequestData(postData, strlen(postData));
request->setTag("POST test");
request->setTag("POST test1");
CCHttpClient::getInstance()->send(request);
request->release();
}
// test 2: set Content-Type
{
CCHttpRequest* request = new CCHttpRequest();
request->setUrl("http://www.httpbin.org/post");
request->setRequestType(CCHttpRequest::kHttpPost);
std::vector<std::string> headers;
headers.push_back("Content-Type: application/json; charset=utf-8");
request->setHeaders(headers);
request->setResponseCallback(this, callfuncND_selector(HttpClientTest::onHttpRequestCompleted));
// write the post data
const char* postData = "visitor=cocos2d&TestSuite=Extensions Test/NetworkTest";
request->setRequestData(postData, strlen(postData));
request->setTag("POST test2");
CCHttpClient::getInstance()->send(request);
request->release();
}
// waiting
m_labelStatusCode->setString("waiting...");