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

@Multipart is not possible to send a charset together with multipart/form-data #3493

Open
1 of 3 tasks
thiagoyf opened this issue Nov 15, 2020 · 4 comments
Open
1 of 3 tasks

Comments

@thiagoyf
Copy link

thiagoyf commented Nov 15, 2020

What kind of issue is this?

  • Question. This issue tracker is not the place for questions. If you want to ask how to do
    something, or to understand why something isn't working the way you expect it to, use Stack
    Overflow. https://stackoverflow.com/questions/tagged/retrofit

  • Bug report. If you’ve found a bug, spend the time to write a failing test. Bugs with tests
    get fixed. Here’s an example: https://gist.github.com/swankjesse/6608b4713ad80988cdc9

  • Feature Request. Start by telling us what problem you’re trying to solve. Often a solution
    already exists! Don’t send pull requests to implement new features without first getting our
    support. Sometimes we leave features out on purpose to keep the project small.

I tried to use retrofit to send requests to a server that has some blocking rules. When I was trying to send a request to my backend with Multipart, it didn't reach my backend. I spent some time investigating why it happened and I found that my requisition lacked charset sent with multipart/form-data.

The code that I had to written on OkHttp:

val mediaType = "multipart/form-data; charset=utf-8".toMediaType()
val headers = Headers.headersOf("Content-Disposition", "form-data; name=\"myjson\"")

val multipartPartBody = """{"body":"hello"}""".toRequestBody()
val multipartBody = MultipartBody.Builder()
                    .setType(mediaType)
                    .addPart(headers, multipartPartBody)
                    .build()

val request = Request.Builder()
                    .url(myUrl)
                    .put(multipartBody)
                    .build()

val response = client.newCall(request).execute()

I couldn't send this way to the backend with Retrofit

I just wanted a way to send a request with this charset with Retrofit

@ssiegler
Copy link

ssiegler commented Dec 1, 2021

It seems like this would also allow to send other multipart types like multipart/related or multipart/mixed. Or is there already some better way to do so using retrofit?

@cuihaifengchina
Copy link

后台服务器 undertow 不支持这种请求,换成tomact就好了,排查下后台

@thiagoyf
Copy link
Author

The way that retrofit builds a multipart/form-data it doesn't allow us to build a request with charset to utf-8 like multipart/form-data; charset=utf-8 which could lead to syntax errors. One example is like

https://www.ibm.com/mysupport/s/question/0D50z000062krW2CAI/encoding-problems-when-using-multipartformdata?language=en_US

@tomridder
Copy link

The way that retrofit builds a multipart/form-data it doesn't allow us to build a request with charset to utf-8 like multipart/form-data; charset=utf-8 which could lead to syntax errors. One example is like

https://www.ibm.com/mysupport/s/question/0D50z000062krW2CAI/encoding-problems-when-using-multipartformdata?language=en_US

do u mean u want to let retrofit do the part of
val mediaType = "multipart/form-data; charset=utf-8".toMediaType()?

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

4 participants