“Multipart body must have at least one part”

北城以北 提交于 2019-12-19 10:32:37

问题


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:


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.



来源:https://stackoverflow.com/questions/44591453/multipart-body-must-have-at-least-one-part

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!