A POST
wihtout specifying a body
#1630
-
Hi! Can anyone explain to me what happens if I make a [Post("/resource/{someId}")]
Task MakePost(string someId); The issue I got is that in such a scenario it seems that the first argument of the function is also sent as body (which is weird). Is this by design or is it an issue? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 4 replies
-
When you make a POST request without specifying a body, the endpoint you're targeting might just treat it as an empty body or lead to an error condition depending on how that endpoint is set-up. Regarding the situation when Can you confirm which library/framework you are using for making the HTTP request? |
Beta Was this translation helpful? Give feedback.
Refit, by design, automatically serializes the first argument of a POST method to JSON and assigns it to the request body when no parameter is explicitly set with [Body] attribute. This is why you're seeing the "string-content" in the body when Refit makes the request.
If you don't want any body in your request, your current solution of adding a [Body] NoBody noBody parameter is good. Another way is to pass it as a null argument, like you mentioned.
The issue isn't explicitly documented because it's part of the automagic that makes Refit easy to use in most common cases.
I hope that answers your question. Don't hesitate to ask if you have any more doubts.