Question

I'm trying to save a PDF from QBO however I'm stuck on this bit: How do i get the IConsumerRequest to return a stream instead of a string? ReadBody only seems to send string rather than binary data...

IConsumerRequest conReq = oSession.Request();
conReq = conReq.Get().WithRawContentType("application/pdf");
string outURL = base_url + "invoice-document/v2/" + realmId + "/" + customerInvoicesWithinDateRange[0].Id.Value;
conReq = conReq.ForUrl(outURL);
conReq = conReq.SignWithToken();
string serviceResponse = conReq.ReadBody();

Thanks

Was it helpful?

Solution

instead of conReeq.ReadBody(), you can do this:

conReq.ToWebResponse().GetResponseStream();

in fact, ReadBody() is simply an extension method on IConsumerRequest, defined as:

public static string ReadBody(this IConsumerRequest request)
{
  HttpWebResponse response = request.ToWebResponse();

  return response.ReadToEnd();
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top