Skip to content

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

Open
@thiagoyf

Description

@thiagoyf

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions