mirror of https://github.com/axmolengine/axmol.git
Update samples/TestCpp/Classes/ExtensionsTest/NetworkTest/HttpClientTest.cpp
Added test to show use of HttpRequest::setHeaders
This commit is contained in:
parent
b3f5a04ad4
commit
e0fe233752
|
@ -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...");
|
||||||
|
|
Loading…
Reference in New Issue