Micronaut Http Request Perform Errors on Encoding Body as Form-Data

I am trying to perform an HTTP request in form-data format to an external server using the Micronaut HTTP Client. However, when I make the request, the server returns an error as if the body is completely empty.

To test if my request was being sent correctly, I made a Node application to capture the request data, then I tested a validated request through postman calling this server, and the Java/Kotlin application also to this server. The content looks exactly the same, as you can see in the following.

Comparing Content of Application Request with Postman Request

If I change the URL in postman and make the same request, it will return success, as you can see in the following print:

Print of Postman Request

Print of a Empty Body Request on Postman

Log of Request

17:07:52.205 [Test worker] WARN  i.m.h.c.n.ssl.NettyClientSslBuilder - HTTP Client is configured to trust all certificates ('insecure-trust-all-certificates' is set to true). Trusting all certificates is not secure and should not be used in production.
17:07:53.692 [default-nioEventLoopGroup-1-2] DEBUG i.m.h.client.netty.DefaultHttpClient - Sending HTTP POST to https://ocd.com/api.php
17:07:53.695 [default-nioEventLoopGroup-1-2] TRACE i.m.h.client.netty.DefaultHttpClient - content-type: multipart/form-data; boundary=36c78120781912df
17:07:53.695 [default-nioEventLoopGroup-1-2] TRACE i.m.h.client.netty.DefaultHttpClient - transfer-encoding: chunked
17:07:53.695 [default-nioEventLoopGroup-1-2] TRACE i.m.h.client.netty.DefaultHttpClient - host: ocd.com
17:07:53.902 [default-nioEventLoopGroup-1-2] TRACE i.m.h.client.netty.DefaultHttpClient - HTTP Client Response Received (200 OK) for Request: POST https://ocd.com/api.php
17:07:53.902 [default-nioEventLoopGroup-1-2] TRACE i.m.h.client.netty.DefaultHttpClient - date: Mon, 22 Jul 2024 20:07:53 GMT
17:07:53.902 [default-nioEventLoopGroup-1-2] TRACE i.m.h.client.netty.DefaultHttpClient - server: Apache
17:07:53.902 [default-nioEventLoopGroup-1-2] TRACE i.m.h.client.netty.DefaultHttpClient - vary: Accept-Encoding
17:07:53.903 [default-nioEventLoopGroup-1-2] TRACE i.m.h.client.netty.DefaultHttpClient - x-frame-options: SAMEORIGIN
17:07:53.903 [default-nioEventLoopGroup-1-2] TRACE i.m.h.client.netty.DefaultHttpClient - x-xss-protection: 1;mode=block
17:07:53.903 [default-nioEventLoopGroup-1-2] TRACE i.m.h.client.netty.DefaultHttpClient - x-content-type-options: nosniff
17:07:53.903 [default-nioEventLoopGroup-1-2] TRACE i.m.h.client.netty.DefaultHttpClient - content-type: application/json; charset=utf-8
17:07:53.903 [default-nioEventLoopGroup-1-2] TRACE i.m.h.client.netty.DefaultHttpClient - x-http2-stream-id: 3
17:07:53.904 [default-nioEventLoopGroup-1-2] TRACE i.m.h.client.netty.DefaultHttpClient - content-length: 1320
17:07:53.904 [default-nioEventLoopGroup-1-2] TRACE i.m.h.client.netty.DefaultHttpClient - Response Body
17:07:53.905 [default-nioEventLoopGroup-1-2] TRACE i.m.h.client.netty.DefaultHttpClient - ----
17:07:53.905 [default-nioEventLoopGroup-1-2] TRACE i.m.h.client.netty.DefaultHttpClient - {"code":400,"status":"Empty input array.nTransfer-Encoding: chunkednHost: ocd..comnContent-Type: multipart/form-data; boundary=36c78120781912dfnnnnnUSER: apachenHOME: /usr/share/httpdnORACLE_HOME: /usr/lib/oracle/21/client64/libnSCRIPT_NAME: /api.phpnREQUEST_URI: /api.phpnQUERY_STRING: nREQUEST_METHOD: POSTnSERVER_PROTOCOL: HTTP/2.0nGATEWAY_INTERFACE: CGI/1.1nREMOTE_PORT: 65321nSCRIPT_FILENAME: /app/ocd/prod/www/api.phpnSERVER_ADMIN: nCONTEXT_DOCUMENT_ROOT: /app/ocd/prod/wwwnCONTEXT_PREFIX: nREQUEST_SCHEME: httpsnDOCUMENT_ROOT: /app/ocd/prod/wwwnREMOTE_ADDR: 135.20.60.219nSERVER_PORT: 443nSERVER_ADDR: 135.122.129.127nSERVER_NAME: nSERVER_SOFTWARE: ApachenSERVER_SIGNATURE: nPATH: /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/binnHTTP_TRANSFER_ENCODING: chunkednHTTP_HOST: ocd..comnCONTENT_TYPE: multipart/form-data; boundary=36c78120781912dfnproxy-nokeepalive: 1nH2_STREAM_TAG: 000nH2_STREAM_ID: nH2_PUSHED_ON: nH2_PUSHED: nH2_PUSH: onnH2PUSH: onnHTTP2: onnSSL_TLS_SNI: ocd..comnHTTPS: onnUNIQUE_ID: Zp68GQVLiVT8r4HwgmdXsgAA0hUnFCGI_ROLE: RESPONDERnPHP_SELF: /api.phpnREQUEST_TIME_FLOAT: 1721678873.2902nREQUEST_TIME: 1721678873nnnnnnnnn","time":"00.0016s","data":[]}
17:07:53.905 [default-nioEventLoopGroup-1-2] TRACE i.m.h.client.netty.DefaultHttpClient - ----

Kotlin Code:

fun requestTickets() {

        val uri: URI = UriBuilder.of(configuration.url)
            .build()


        val bodyBuilder = MultipartBody.builder()
            .addPart("auth_user", configuration.authUser)
            .addPart("auth_key", configuration.authKey)
            .addPart("object", configuration.objects)
            .addPart("method", configuration.method)
            .addPart("queue_arr[]", "BRAZIL_SD")
            .addPart("event_id_last", "28218371")

        val body = bodyBuilder.build()

        val req = HttpRequest.POST(uri, body)
            //.contentType(MediaType.MULTIPART_FORM_DATA_TYPE)
            .contentType(MediaType.MULTIPART_FORM_DATA)
            //.contentType(MediaType.FORM)
            // .contentType(MediaType.APPLICATION_FORM_URLENCODED_TYPE)

        val res = httpClient.toBlocking()
            .exchange(req, String::class.java)

    }

Note I’ve changed the contentType for all those options commented above.

Thank you

  • Changing MediaType

New contributor

Roberto Alves is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật