Closed ojhwel closed 7 months ago
so the .toSummary().asString()
is an approximation and is NOT the exact thing that was sent to the server, they may differ. For example, the main content header is actually sent, its just not in the summary. This is because there are aspects of multipart processing handled by the Java HttpClient that are lost to unirest, but others could be better for sure. I'm going to create a test to expose which parts are a defect with sending the data to a server and which ones are a issue with the summary
Thanks for the quick response. The trigger for me looking into this was a 415 Unsupported Media Type response citing "application/octet-stream", although the server side folks couldn't immediately say which part was the culprit. That's when I added the Interceptor.
So a little more information. The Summary is indded way off, for a bunch of reasons, mostly related to the idea that you can always call for the summary at any point in the lifecycle, before the request was made. and particularly for multipart forms which don't fully come together until the end. So I consider that a defect of sorts, Its never going to be 100%, but it needs to get closer.
As for the actual behavior of the Unirest. We have a nice suite of behavioral tests that stand up a little Jetty server that takes requests and echos back what was sent. This is the most accurate representation of the request.
You can see a example test here: https://github.com/Kong/unirest-java/blob/main/unirest-bdd-tests/src/test/java/BehaviorTests/MultiPartFormPostingTest.java#L426-L451
This has uncovered a few things that might result in your 415:
multipart/form-data; boundary=4ebf68bc-70f8-462b-b3a5-48dadb236af3;charset=UTF-8
It might be that the server is looking for a strict "multipart/form-data" value and is not expecting the additional params.
4.2.9 is on its way out the door and has a more accurate summary
Thanks, that works perfectly for our purposes.
closing this as complete
Describe the bug I'm trying to POST a multipart message consisting of a file and some JSON metadata, but the outgoing request is missing the appropriate content types.
To Reproduce
Expected behavior I'd expect the request to look something like this:
Screenshots What I'm getting, as printed by
.toSummary().asString()
, is this:.header()
call but I don't think that should be necessary when I have twofield()
s.Environmental Data: