Yesterday wrote the simple use of curl, met a few pits, today with httpclient write sample or met pit ~650) this.width=650; "Src=" Http://img.baidu.com/hi/jx2/j_0012.gif " alt= "J_0012.gif"/>
According to the information on the Internet always meet the problem ... Should be the version is not the same!!! Let me tell you how to use HttpClient.
The first step is to introduce header files and namespaces
#include "network/httpclient.h" using namespace cocos2d::network;
But this does not work, compile the words will be error, unresolved external symbols ....
This needs to add the network library, and the way to add the library is a bit different from before. 3.x some of the additional items have been streamlined in the project, such as Libcocosstudio, Libextensions, Libgui and so on, which need to be added manually.
How to add: find the entire solution in Solution Explorer, right-click, choose Add, Existing project. In the popup dialog box, locate the "project directory \cocos2d\cocos\network\proj.win32\libnetwork" click OK
When you're done adding it, you'll reference it, such as:
650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M02/54/5B/wKioL1SAHaHBjOc_AAJhI1CIkrs838.jpg "title=" Qq20141204163609.png "style=" Float:none; "alt=" wkiol1sahahbjoc_aajhi1cikrs838.jpg "/>
Go to "References", select "Add New Reference", add libnetwork .... just blame !!!
You also need to add libcurl_imp.lib, because HttpClient is the package for curl!
650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M01/54/5C/wKiom1SAHerhLX4VAAF_NAPwhtc403.jpg "title=" Qq20141204163923.png "alt=" wkiom1saherhlx4vaaf_napwhtc403.jpg "/> The code of the sample to the following code:
void helloworld::touchended (Touch *ptouch, Event *pevent) {log ("helloworld::touchended");//Create Request Object HttpRequest * Request = new HttpRequest ()///Set the requested Urlrequest->seturl ("www.baidu.com");//set to get mode Request->setrequesttype ( Httprequest::type::get);//sets the callback Request->setresponsecallback for the response (Cc_callback_2 (helloworld::o Nhttprequestcompleted, this)); Request->settag ("test");//Send Request Httpclient::getinstance ()->send (request);// Release request Request->release ();}
void helloworld::onhttprequestcompleted (HttpClient *sender, HttpResponse *response) {if (Response->issucceed ()) { Mlabel->setstring ("Connect successfully!");} Else{char Buf[128];long res = Response->getresponsecode () sprintf (buf, "code:%i", res); mlabel->setstring (BUF);}}
You can achieve the effect of CURL Sample!!!
This is httpclient preliminary use of the instructions, there should be a follow-up article!
If there are deficiencies, please point out that together to exchange growth!
This article is from the "Little Wolf zer" blog, please make sure to keep this source http://9151482.blog.51cto.com/9141482/1586359
COCOS2DX 3.3RC0 Diary (ii) use of the------HttpClient