Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

上传文件,增加formData参数,会有产生两个。 如图 #52

Closed
XiaoWensc opened this issue Dec 15, 2021 · 6 comments
Closed

Comments

@XiaoWensc
Copy link

image
image

@liangjingkanji
Copy link
Owner

好的, 稍等我复现下问题. 仅上传文件存在这个问题是吧

@XiaoWensc
Copy link
Author

是的

@liangjingkanji
Copy link
Owner

demo中无法复现, 你最好确认下(可能是输出日志工具的问题)或者fork仓库复现

上传文件实现代码在buildRequest, 你也可以使用断点调试查看问题

override fun buildRequest(): Request {
    val body = if (body != null) body else {
        val form = formBody.build()
        try {
            partBody.build()
            for (i in 0 until form.size) { // 如果存在文件就开始使用multiPartBody方式上传
                val name = form.name(i)
                val value = form.value(i)
                partBody.addFormDataPart(name, value)
            }
            partBody.setType(mediaType).build()
        } catch (e: IllegalStateException) {
            form
        }
    }

    return okHttpRequest.method(method.name, body)
        .url(httpUrl.build())
        .setConverter(converter)
        .build()
}

@liangjingkanji
Copy link
Owner

无法复现

@XiaoWensc
Copy link
Author

我找到出现问题的原因了。
因为在RequestInterceptor中 buildRequest() 获取过一次Request对象,导致重复执行buildRequest(), 从而出现了相同的参数

@liangjingkanji
Copy link
Owner

欢迎下次讨论

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants