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

@ -101,18 +101,40 @@ void HttpClientTest::onMenuGetTestClicked(cocos2d::CCObject *sender)
void HttpClientTest::onMenuPostTestClicked(cocos2d::CCObject *sender) void HttpClientTest::onMenuPostTestClicked(cocos2d::CCObject *sender)
{ {
// test 1
{
CCHttpRequest* request = new CCHttpRequest(); CCHttpRequest* request = new CCHttpRequest();
request->setUrl("http://www.httpbin.org/post"); request->setUrl("http://www.httpbin.org/post");
request->setRequestType(CCHttpRequest::kHttpPost); request->setRequestType(CCHttpRequest::kHttpPost);
request->setResponseCallback(this, callfuncND_selector(HttpClientTest::onHttpRequestCompleted)); request->setResponseCallback(this, callfuncND_selector(HttpClientTest::onHttpRequestCompleted));
// write the post data // 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->setRequestData(postData, strlen(postData));
request->setTag("POST test"); request->setTag("POST test1");
CCHttpClient::getInstance()->send(request); CCHttpClient::getInstance()->send(request);
request->release(); 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 // waiting
m_labelStatusCode->setString("waiting..."); m_labelStatusCode->setString("waiting...");