根据要求,我将调用REST服务,该服务将发送附件或文件作为HTTP正文中文件的二进制内容以及内容类型头的适当值,我需要打开内容在它的特定编辑器中.
我正在使用RestSharp,下面是相同的代码:例如.如果附件是.doc-
var client = new RestClient(Properties.Settings.Default.RestServicesUrl + Constants.RestTicketServices);
var restRq = new RestRequest(Constants.SearchTicket);
restRq.Method = Method.GET;
restRq.RequestFormat = DataFormat.Json;
restRq.AddParameter("account_id", "10);
client.Authenticator = new HttpBasicAuthenticator(Properties.Settings.Default.RestAuthenticationUserName, Properties.Settings.Default.RestAuthenticationPass);
IRestResponse rest = client.Execute(restRq);
Run Code Online (Sandbox Code Playgroud)
所以,在这个电话之后:
rest.ContentType ="application/vnd.openxmlformats-officedocument.wordprocessingml.document; charset = utf-8"
rest.Content =具有word文档的二进制数据,依此类推....
基本上,我正在寻找如何读取二进制内容并在关联的编辑器中打开它.
.xls - Excel .doc - Word .pdf - Adobe等等.....
这是晚了一年,但最近我搜索了OP问题的答案并找到了 - 只需替换代码的最后一行:
byte[] bytes = client.DownloadData(restRq);
Run Code Online (Sandbox Code Playgroud)
如果你想要一个IRestResponse,那么你可以通过以下方式获得RawBytes:
IRestResponse rest = client.Execute(restRq);
byte[] bytes = rest.RawBytes;
Run Code Online (Sandbox Code Playgroud)
RestSharp源中解释了更有趣的方法.
| 归档时间: |
|
| 查看次数: |
3010 次 |
| 最近记录: |