How to consume a file with a ServiceStack client

后端 未结 4 667
盖世英雄少女心
盖世英雄少女心 2021-02-01 23:34

I am trying to use ServiceStack to return a file to a ServiceStack client in a RESTful manner.

I have read other questions on SO (here and here) which advise using HttpR

4条回答
  •  不知归路
    2021-02-02 00:27

    You can intercept the response prior to it being handled by using a response filter, like below:

    ServiceClientBase.HttpWebResponseFilter = response =>
    {
        if (response.Headers["Content-Disposition"] != null)
        {
            var t = response.DownloadText();
            Console.WriteLine(t);
        }
    };
    

    However, this is not the best way to handle it, since the actual call to client.Method() will result in an ArgumentException when the client attempts to read the response stream (since it has been read previously by response.DownloadFile(...). I haven't yet figured out a way to handle it gracefully, but I 'll update my answer if I do.

提交回复
热议问题