1

我試圖從QBO保存一個PDF,但我被卡在這一點: 我如何讓IConsumerRequest返回一個流而不是一個字符串? ReadBody似乎只發送字符串,而不是二進制數據...用Devdefined的IConsumerRequest保存PDF

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(); 

感謝

回答

4

代替conReeq.ReadBody(),你可以這樣做:

conReq.ToWebResponse().GetResponseStream(); 
其實

,ReadBody( )簡單地是IConsumerRequest上的擴展方法,定義爲:

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

    return response.ReadToEnd(); 
} 
+0

甜。謝謝您的幫助。 – safetyOtter