Skip to content

Commit c0a31d3

Browse files
committed
Merge pull request android-async-http#166 from tompesman/master
Accept HTTP 204 JSON response
2 parents 65dc6f2 + bce069d commit c0a31d3

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

src/com/loopj/android/http/JsonHttpResponseHandler.java

+11-6
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
package com.loopj.android.http;
2020

21+
import org.apache.http.HttpStatus;
2122
import org.json.JSONArray;
2223
import org.json.JSONException;
2324
import org.json.JSONObject;
@@ -94,12 +95,16 @@ public void onFailure(Throwable e, JSONArray errorResponse) {}
9495

9596
@Override
9697
protected void sendSuccessMessage(int statusCode, String responseBody) {
97-
try {
98-
Object jsonResponse = parseResponse(responseBody);
99-
sendMessage(obtainMessage(SUCCESS_JSON_MESSAGE, new Object[]{statusCode, jsonResponse}));
100-
} catch(JSONException e) {
101-
sendFailureMessage(e, responseBody);
102-
}
98+
if (statusCode != HttpStatus.SC_NO_CONTENT){
99+
try {
100+
Object jsonResponse = parseResponse(responseBody);
101+
sendMessage(obtainMessage(SUCCESS_JSON_MESSAGE, new Object[]{statusCode, jsonResponse}));
102+
} catch(JSONException e) {
103+
sendFailureMessage(e, responseBody);
104+
}
105+
}else{
106+
sendMessage(obtainMessage(SUCCESS_JSON_MESSAGE, new Object[]{statusCode, new JSONObject()}));
107+
}
103108
}
104109

105110

0 commit comments

Comments
 (0)