Skip to content
Discussion options

You must be logged in to vote

byte[] is not special-cased on the response path, so Refit hands the body to the JSON serializer, which is why a raw binary body fails to "deserialize".

For raw binary responses use one of the types Refit treats as raw content:

  • Stream
  • HttpResponseMessage
  • HttpContent

Examples:

[Get("/signature")]
Task<Stream> GetDoc();

// keep status/headers access:
[Get("/signature")]
Task<IApiResponse<HttpResponseMessage>> GetDoc();

With Stream you read the bytes yourself:

await using var s = await api.GetDoc();
using var ms = new MemoryStream();
await s.CopyToAsync(ms);
var bytes = ms.ToArray();

If you specifically need byte[], plug in a content serializer that returns the raw bytes for that type, or…

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by glennawatson
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants