From 753335726a846e08f7f7e537b3ae825fafae622f Mon Sep 17 00:00:00 2001 From: "byeonggee.seo" Date: Tue, 3 Feb 2015 16:28:23 +0900 Subject: [PATCH 1/6] receive content data even though status code is not 2xx --- cocos/network/HttpAsynConnection.m | 12 +++++----- .../lib/Cocos2dxHttpURLConnection.java | 22 ++++++++++++++----- 2 files changed, 22 insertions(+), 12 deletions(-) diff --git a/cocos/network/HttpAsynConnection.m b/cocos/network/HttpAsynConnection.m index 63892ff282..8058485cc0 100755 --- a/cocos/network/HttpAsynConnection.m +++ b/cocos/network/HttpAsynConnection.m @@ -87,13 +87,13 @@ | “205” ; Reset Content | “206” ; Partial Content */ - if (responseCode < 200 || responseCode >= 300) - {// something went wrong, abort the whole thing + // if (responseCode < 200 || responseCode >= 300) + // {// something went wrong, abort the whole thing - [connection cancel]; - finish = true; - return; - } + // [connection cancel]; + // finish = true; + // return; + // } [responseData setLength:0]; } diff --git a/cocos/platform/android/java/src/org/cocos2dx/lib/Cocos2dxHttpURLConnection.java b/cocos/platform/android/java/src/org/cocos2dx/lib/Cocos2dxHttpURLConnection.java index 53b25e6100..c0d9c5f7c4 100644 --- a/cocos/platform/android/java/src/org/cocos2dx/lib/Cocos2dxHttpURLConnection.java +++ b/cocos/platform/android/java/src/org/cocos2dx/lib/Cocos2dxHttpURLConnection.java @@ -260,8 +260,17 @@ public class Cocos2dxHttpURLConnection } static byte[] getResponseContent(HttpURLConnection http) { - try { - DataInputStream in = new DataInputStream(http.getInputStream()); + DataInputStream in; + try { + in = new DataInputStream(http.getInputStream()); + } catch (IOException e) { + in = new DataInputStream(http.getErrorStream()); + } catch (Exception e) { + Log.e("Cocos2dxHttpURLConnection exception", e.toString()); + return null; + } + + try { byte[] buffer = new byte[1024]; int size = 0; ByteArrayOutputStream bytestream = new ByteArrayOutputStream(); @@ -272,12 +281,13 @@ public class Cocos2dxHttpURLConnection byte retbuffer[] = bytestream.toByteArray(); bytestream.close(); return retbuffer; - } catch (Exception e) { - Log.e("Cocos2dxHttpURLConnection exception", e.toString()); - } + } catch (Exception e) { + Log.e("Cocos2dxHttpURLConnection exception", e.toString()); + } + return null; } - + static int getResponseCode(HttpURLConnection http) { int code = 0; try { From 91b0104fd0e05db88048f6d00c33aef41562938b Mon Sep 17 00:00:00 2001 From: seobyeongky Date: Fri, 27 Feb 2015 21:31:33 +0900 Subject: [PATCH 2/6] Fix an issue with iOS HTTP Request code (https://github.com/cocos2d/cocos2d-x/pull/10543) --- cocos/network/HttpAsynConnection.m | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/cocos/network/HttpAsynConnection.m b/cocos/network/HttpAsynConnection.m index 8058485cc0..a3a62499af 100755 --- a/cocos/network/HttpAsynConnection.m +++ b/cocos/network/HttpAsynConnection.m @@ -87,13 +87,12 @@ | “205” ; Reset Content | “206” ; Partial Content */ - // if (responseCode < 200 || responseCode >= 300) - // {// something went wrong, abort the whole thing - - // [connection cancel]; - // finish = true; - // return; - // } + if (responseCode < 200 || responseCode >= 300) + {// something went wrong, abort the whole thing + self.responseError = [NSError errorWithDomain:@"CCBackendDomain" + code:responseCode + userInfo:@{NSLocalizedDescriptionKey: @"Bad HTTP Response Code"}]; + } [responseData setLength:0]; } From 3811c9f1a3ded98ce91885af0cedd7e031f37e50 Mon Sep 17 00:00:00 2001 From: "byeonggee.seo" Date: Tue, 3 Mar 2015 16:33:35 +0900 Subject: [PATCH 3/6] connError added --- cocos/network/HttpAsynConnection.h | 1 + cocos/network/HttpAsynConnection.m | 4 +++- cocos/network/HttpClient-ios.mm | 9 ++++++++- 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/cocos/network/HttpAsynConnection.h b/cocos/network/HttpAsynConnection.h index cd3b2cc78e..ab0ba7a9af 100644 --- a/cocos/network/HttpAsynConnection.h +++ b/cocos/network/HttpAsynConnection.h @@ -46,6 +46,7 @@ @property (readonly) NSString *statusString; @property (strong) NSError *responseError; +@property (strong) NSError *connError; @property (strong) NSURLConnection *conn; diff --git a/cocos/network/HttpAsynConnection.m b/cocos/network/HttpAsynConnection.m index 8058485cc0..23683a5f19 100755 --- a/cocos/network/HttpAsynConnection.m +++ b/cocos/network/HttpAsynConnection.m @@ -34,6 +34,7 @@ @synthesize responseCode; @synthesize statusString; @synthesize responseError; +@synthesize connError; @synthesize conn; @synthesize finish; @synthesize runLoop; @@ -46,6 +47,7 @@ responseData = [NSMutableData new]; getDataTime = 0; responseError = nil; + connError = nil; // create the connection with the target request and this class as the delegate self.conn = [[NSURLConnection alloc] initWithRequest:request @@ -118,7 +120,7 @@ didFailWithError:(NSError *)error { //NSLog(@"Load failed with error %@", [error localizedDescription]); - responseError = [error copy]; + connError = [error copy]; finish = true; } diff --git a/cocos/network/HttpClient-ios.mm b/cocos/network/HttpClient-ios.mm index 9a63e5e265..a0d4480b25 100644 --- a/cocos/network/HttpClient-ios.mm +++ b/cocos/network/HttpClient-ios.mm @@ -243,11 +243,18 @@ static int processTask(HttpRequest *request, NSString* requestType, void *stream } //if http connection return error + if (httpAsynConn.connError != nil) + { + NSString* errorString = [httpAsynConn.connError localizedDescription]; + strcpy(errorBuffer, [errorString UTF8String]); + return 0; + } + + //if http response got error, just log the error if (httpAsynConn.responseError != nil) { NSString* errorString = [httpAsynConn.responseError localizedDescription]; strcpy(errorBuffer, [errorString UTF8String]); - return 0; } *responseCode = httpAsynConn.responseCode; From 73e01c0d5e9f68fb29208a89c9587b5750fe77da Mon Sep 17 00:00:00 2001 From: Dale Stammen Date: Thu, 19 Mar 2015 05:53:37 -0700 Subject: [PATCH 4/6] added missing PerformanceParticle3DTest.cpp to WP8 project --- .../cpp-testsComponent/cpp-testsComponent.vcxproj | 2 ++ .../cpp-testsComponent.vcxproj.filters | 10 ++++++++-- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/tests/cpp-tests/proj.wp8-xaml/cpp-testsComponent/cpp-testsComponent.vcxproj b/tests/cpp-tests/proj.wp8-xaml/cpp-testsComponent/cpp-testsComponent.vcxproj index 29f9305c8f..6815dc2f31 100644 --- a/tests/cpp-tests/proj.wp8-xaml/cpp-testsComponent/cpp-testsComponent.vcxproj +++ b/tests/cpp-tests/proj.wp8-xaml/cpp-testsComponent/cpp-testsComponent.vcxproj @@ -247,6 +247,7 @@ + @@ -451,6 +452,7 @@ + diff --git a/tests/cpp-tests/proj.wp8-xaml/cpp-testsComponent/cpp-testsComponent.vcxproj.filters b/tests/cpp-tests/proj.wp8-xaml/cpp-testsComponent/cpp-testsComponent.vcxproj.filters index 2da7b9eaab..f05c7c4f31 100644 --- a/tests/cpp-tests/proj.wp8-xaml/cpp-testsComponent/cpp-testsComponent.vcxproj.filters +++ b/tests/cpp-tests/proj.wp8-xaml/cpp-testsComponent/cpp-testsComponent.vcxproj.filters @@ -348,7 +348,7 @@ {65f104c8-5b02-4c44-ab8b-a8e7289e5c7a} - + @@ -918,6 +918,9 @@ Classes\CocosStudio3DTest + + Classes\PerformanceTest + @@ -1685,7 +1688,10 @@ Classes\CocosStudio3DTest - + + + Classes\PerformanceTest + From a9cafb14cb7e433267317dd93031f2457659030b Mon Sep 17 00:00:00 2001 From: minggo Date: Thu, 19 Mar 2015 21:23:16 +0800 Subject: [PATCH 5/6] [ci skip]update CHANGELOG --- CHANGELOG | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/CHANGELOG b/CHANGELOG index c491671ba3..5210899542 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,8 +1,9 @@ -cocos2d-x-3.5 Mar.20 2015 +cocos2d-x-3.5 Mar.23 2015 [NEW] EditBox: support Color4B [FIX] AutoRelasePool: memory leak if adding an element into pool when releasing auto release pool [FIX] FileUtils: getWritablePath() will not return corrent setted writable path on Mac & Windows + [FIX] HttpAsynConnection: can not get error content if responseCode < 200 or responseCode >= 300 cocos2d-x-3.5rc0 Mar.13 2015 [NEW] CocosStudio: add callback when loading a CSB file From 43a5a65ff449aa7e326efad4d005d0658908160e Mon Sep 17 00:00:00 2001 From: minggo Date: Thu, 19 Mar 2015 21:24:36 +0800 Subject: [PATCH 6/6] [ci skip]update CHANGELOG --- CHANGELOG | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG b/CHANGELOG index 5210899542..1055c36377 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -3,7 +3,7 @@ cocos2d-x-3.5 Mar.23 2015 [FIX] AutoRelasePool: memory leak if adding an element into pool when releasing auto release pool [FIX] FileUtils: getWritablePath() will not return corrent setted writable path on Mac & Windows - [FIX] HttpAsynConnection: can not get error content if responseCode < 200 or responseCode >= 300 + [FIX] HttpAsynConnection: can not get error content if response code less than 200 or response code greater or equal than 300 cocos2d-x-3.5rc0 Mar.13 2015 [NEW] CocosStudio: add callback when loading a CSB file