title: How to pass a pdf from WebAPI and read the pdf from the MVC Controller?
body: <p>I have a Web API service that should return a PDF.
  <br/>I am then trying to call that WebAPI method to read the PDF.</p>
  
  <p>Here is my API Method:</p>
  
  <pre><code>    [HttpPost]
      [Route("GetTestPDF")]
      public HttpResponseMessage TestPDF()
      {
          HttpResponseMessage response = new HttpResponseMessage(HttpStatusCode.OK);
          response.Content = new StreamContent(new FileStream(@"C:\MyPath\MyFile.pdf", FileMode.Open, FileAccess.Read));
          response.Content.Headers.ContentDisposition = new System.Net.Http.Headers.ContentDispositionHeaderValue("attachment");
          response.Content.Headers.ContentDisposition.FileName = "MyFile.pdf";
          response.Content.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue("application/pdf");
  
          return Request.CreateResponse(HttpStatusCode.OK, response);
      }
  </code></pre>
  
  <p>However when I go to read the response I don't see the pdf contents.  I am not sure where I am going wrong with this.</p>
  
  <p>Controller Method:</p>
  
  <pre><code>public ActionResult GetPDF()
          {
              var response = new HttpResponseMessage();
  
              using (HttpClient httpClient = new HttpClient())
              {
                  httpClient.BaseAddress = new Uri(@"my local host");                               
                  response = httpClient.PostAsync(@"api/job/GetTestPDF", new StringContent(string.Empty)).Result;
              }
  
              var whatisThis = response.Content.ReadAsStringAsync().Result;
              return new FileContentResult(Convert.FromBase64String(response.Content.ReadAsStringAsync().Result), "application/pdf");
          }
  </code></pre>
  
  <p>When I examine whatisThis variable I see the content type and the content dispostion correctly set from my API.  However I don't see the content of the PDF.</p>
  
  <p>How can I read the PDF content?</p>
  
  <p>EDIT:</p>
  
  <p>If I read the content as a string in my MVC site I see. (I don't see the actual content of the file)</p>
  
  <pre><code>{"Version":{"_Major":1,"_Minor":1,"_Build":-1,"_Revision":-1},"Content":{"Headers":[{"Key":"Content-Disposition","Value":["attachment; filename=MyFile.pdf"]},{"Key":"Content-Type","Value":["application/pdf"]}]},"StatusCode":200,"ReasonPhrase":"OK","Headers":[],"RequestMessage":null,"IsSuccessStatusCode":true}
  </code></pre>
  
  <p>I stepped through the WebAPI and it is successfully reading and setting the response.Content with the file contents.</p>
  
  <p>Still not sure if this is an issue on the WebAPI side or the MVC side.</p>