Merge pull request #2623 from zynga/XMLHttpRequest_cchttpclient

fixed #2092: Fixed setHeader while Android had problems with stringstreams.
This commit is contained in:
James Chen 2013-05-23 06:34:50 -07:00
commit 0a20c73f68
1 changed files with 14 additions and 7 deletions

View File

@ -139,15 +139,21 @@ void MinXmlHttpRequest::_setHttpRequestHeader() {
std::vector<string> header; std::vector<string> header;
for (std::map<string,string>::iterator it = request_header.begin(); it != request_header.end(); ++it) { for (std::map<string,string>::iterator it = request_header.begin(); it != request_header.end(); ++it) {
const char* first = it->first.c_str();
const char* second = it->second.c_str();
size_t len = sizeof(char) * (strlen(first) + 3 + strlen(second));
char* test = (char*) malloc(len);
memset(test, 0,len);
stringstream value_s; strcpy(test, first);
const char* value; strcpy(test + strlen(first) , ": ");
strcpy(test + strlen(first) + 2, second);
header.push_back(test);
value_s << it->first << ": " << it->second; free(test);
value = value_s.str().c_str();
header.push_back(value);
} }
if (!header.empty()) { if (!header.empty()) {
@ -252,6 +258,7 @@ MinXmlHttpRequest::MinXmlHttpRequest() : onreadystateCallback(NULL), isNetwork(t
http_header.clear(); http_header.clear();
request_header.clear(); request_header.clear();
withCredentialsValue = true;
cx = ScriptingCore::getInstance()->getGlobalContext(); cx = ScriptingCore::getInstance()->getGlobalContext();
cc_request = new cocos2d::extension::CCHttpRequest(); cc_request = new cocos2d::extension::CCHttpRequest();
} }
@ -736,7 +743,7 @@ JS_BINDED_FUNC_IMPL(MinXmlHttpRequest, setRequestHeader)
JSStringWrapper w2(jsValue); JSStringWrapper w2(jsValue);
field = w1; field = w1;
value = w2; value = w2;
// Populate the request_header map. // Populate the request_header map.
_setRequestHeader(field, value); _setRequestHeader(field, value);