1
votes

I have a Web API REST service method, which returns the pdf file. And the code is as follows:

 string content = some byte array;

            HttpResponseMessage result = new HttpResponseMessage(HttpStatusCode.OK);
            result.Content = new StringContent(content);
            //a text file is actually an octet-stream (pdf, etc)
            result.Content.Headers.ContentType = new MediaTypeHeaderValue("application/pdf");
            //we used attachment to force download
            result.Content.Headers.ContentDisposition = new ContentDispositionHeaderValue("attachment");
            result.Content.Headers.ContentDisposition.FileName = "mypdf.pdf";
            return result;

My doubt is for the other methods in the API, I used content negotiation for the media type of the response. Do I need to use the content negotiation here also?? Is it need here or not?

1
I agree with Darrel below...also note that, if your content is byte array, you can use ByteArrayContent - Kiran Challa

1 Answers

2
votes

No. Conneg is a purely optional thing. If your resource only has a application/pdf representation then so be it.