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)
|
||||||
{
|
{
|
||||||
CCHttpRequest* request = new CCHttpRequest();
|
// test 1
|
||||||
request->setUrl("http://www.httpbin.org/post");
|
{
|
||||||
request->setRequestType(CCHttpRequest::kHttpPost);
|
CCHttpRequest* request = new CCHttpRequest();
|
||||||
request->setResponseCallback(this, callfuncND_selector(HttpClientTest::onHttpRequestCompleted));
|
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/NetworkTest";
|
||||||
|
request->setRequestData(postData, strlen(postData));
|
||||||
|
|
||||||
|
request->setTag("POST test1");
|
||||||
|
CCHttpClient::getInstance()->send(request);
|
||||||
|
request->release();
|
||||||
|
}
|
||||||
|
|
||||||
// write the post data
|
// test 2: set Content-Type
|
||||||
const char* postData = "visitor=cocos2d&TestSuite=Extensions Test/NetowrkTest";
|
{
|
||||||
request->setRequestData(postData, strlen(postData));
|
CCHttpRequest* request = new CCHttpRequest();
|
||||||
|
request->setUrl("http://www.httpbin.org/post");
|
||||||
request->setTag("POST test");
|
request->setRequestType(CCHttpRequest::kHttpPost);
|
||||||
CCHttpClient::getInstance()->send(request);
|
std::vector<std::string> headers;
|
||||||
request->release();
|
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