From 753335726a846e08f7f7e537b3ae825fafae622f Mon Sep 17 00:00:00 2001 From: "byeonggee.seo" Date: Tue, 3 Feb 2015 16:28:23 +0900 Subject: [PATCH] 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 {