mirror of
https://github.com/zhigang1992/react-native.git
synced 2026-04-29 04:35:36 +08:00
fix POST/PUT/PATCH has no body redbox, when xhr is used without body
Summary: … by passing a empty body fix #3371 referring to https://github.com/square/okhttp/pull/1559/files Closes https://github.com/facebook/react-native/pull/4518 Reviewed By: svcscm Differential Revision: D2753086 Pulled By: lexs fb-gh-sync-id: 5c486b127b194b29cd0f8a2cb9a1ef19449109e3
This commit is contained in:
committed by
facebook-github-bot-9
parent
c2b38c9113
commit
c60b581327
@@ -136,7 +136,7 @@ public final class NetworkingModule extends ReactContextBaseJavaModule {
|
|||||||
requestBuilder.headers(requestHeaders);
|
requestBuilder.headers(requestHeaders);
|
||||||
|
|
||||||
if (data == null) {
|
if (data == null) {
|
||||||
requestBuilder.method(method, null);
|
requestBuilder.method(method, RequestBodyUtil.getEmptyBody(method));
|
||||||
} else if (data.hasKey(REQUEST_BODY_KEY_STRING)) {
|
} else if (data.hasKey(REQUEST_BODY_KEY_STRING)) {
|
||||||
if (contentType == null) {
|
if (contentType == null) {
|
||||||
onRequestError(requestId, "Payload is set but no content-type header specified");
|
onRequestError(requestId, "Payload is set but no content-type header specified");
|
||||||
|
|||||||
@@ -27,6 +27,7 @@ import com.squareup.okhttp.MediaType;
|
|||||||
import com.squareup.okhttp.RequestBody;
|
import com.squareup.okhttp.RequestBody;
|
||||||
import com.squareup.okhttp.internal.Util;
|
import com.squareup.okhttp.internal.Util;
|
||||||
import okio.BufferedSink;
|
import okio.BufferedSink;
|
||||||
|
import okio.ByteString;
|
||||||
import okio.Okio;
|
import okio.Okio;
|
||||||
import okio.Source;
|
import okio.Source;
|
||||||
|
|
||||||
@@ -112,4 +113,15 @@ import okio.Source;
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a empty RequestBody if required by the http method spec, otherwise use null
|
||||||
|
*/
|
||||||
|
public static RequestBody getEmptyBody(String method) {
|
||||||
|
if (method.equals("POST") || method.equals("PUT") || method.equals("PATCH")) {
|
||||||
|
return RequestBody.create(null, ByteString.EMPTY);
|
||||||
|
} else {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user