“Multipart body must have at least one part”

2019-05-26 02:00发布

In previous asked question (react-native upload pictures on android) described request with param "FormData", but I requested GET request without data and got same message!

react-native app with ProGuard enabled = true

App crashed on first request.

06-16 14:00:30.971: E/AndroidRuntime(14321): java.lang.IllegalStateException: Multipart body must have at least one part.
06-16 14:00:30.971: E/AndroidRuntime(14321):    at okhttp3.MultipartBody$Builder.build(SourceFile:327)
06-16 14:00:30.971: E/AndroidRuntime(14321):    at com.facebook.react.modules.network.NetworkingModule.sendRequest(SourceFile:309)
06-16 14:00:30.971: E/AndroidRuntime(14321):    at java.lang.reflect.Method.invoke(Native Method)
06-16 14:00:30.971: E/AndroidRuntime(14321):    at java.lang.reflect.Method.invoke(Method.java:372)
06-16 14:00:30.971: E/AndroidRuntime(14321):    at com.facebook.react.bridge.BaseJavaModule$b.a(SourceFile:345)
06-16 14:00:30.971: E/AndroidRuntime(14321):    at com.facebook.react.cxxbridge.JavaModuleWrapper.invoke(SourceFile:136)
06-16 14:00:30.971: E/AndroidRuntime(14321):    at com.facebook.react.bridge.queue.NativeRunnable.run(Native Method)
06-16 14:00:30.971: E/AndroidRuntime(14321):    at android.os.Handler.handleCallback(Handler.java:739)
06-16 14:00:30.971: E/AndroidRuntime(14321):    at android.os.Handler.dispatchMessage(Handler.java:95)
06-16 14:00:30.971: E/AndroidRuntime(14321):    at com.facebook.react.bridge.queue.a.dispatchMessage(SourceFile:31)
06-16 14:00:30.971: E/AndroidRuntime(14321):    at android.os.Looper.loop(Looper.java:135)
06-16 14:00:30.971: E/AndroidRuntime(14321):    at com.facebook.react.bridge.queue.MessageQueueThreadImpl$3.run(SourceFile:196)
06-16 14:00:30.971: E/AndroidRuntime(14321):    at java.lang.Thread.run(Thread.java:818)

Update: Here is wrong part, where this._query was empty object:

let fd = new FormData;
forEach(this._query, (value, key) => {
    fd.append(key, value)
});

params.body = fd;

1条回答
你好瞎i
2楼-- · 2019-05-26 02:37

Multipart body must have at least one part. This message is about wrong arguments for fetch function passed from JavaScript code to alternative function in Java.

I tried to pass body as empty FormData, so message about body without any part of it.

查看更多
登录 后发表回答