Unable to obtain response header information #1698
-
|
When I return a FileResult in the API, I use the browser developer tools to view the request details, view the request response, and there is indeed a head information in the response, but when I use refit to get the response, I find that there is no head information |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
|
To read response headers with Refit, change the method return type so Refit hands you the response, not just the deserialized body. By default Refit returns only the body, so headers are discarded. Use one of:
[Get("/download")]
Task<HttpResponseMessage> Download();
// or
[Get("/download")]
Task<IApiResponse<Stream>> Download();Then: var resp = await api.Download();
var disposition = resp.Content.Headers.ContentDisposition; // for HttpResponseMessage
// or
var disposition = resp.ContentHeaders?.ContentDisposition; // for IApiResponse<T>Note that some headers (like Content-Disposition, Content-Type, Content-Length) live on Content.Headers / ContentHeaders, not the top-level response Headers, which is why a plain body return type never exposes them. |
Beta Was this translation helpful? Give feedback.
To read response headers with Refit, change the method return type so Refit hands you the response, not just the deserialized body. By default Refit returns only the body, so headers are discarded.
Use one of:
Then: