(转载请注明来源:cnblogs coder-fang)
1。获取文件方式:
var param = new Dictionary<string, string> { {"id", appmodel.imageid.ToString()}, {"isdownload","1"} }; try { HttpContent httpContent = new FormUrlEncodedContent(param); HttpClient client = new HttpClient(); httpContent.Headers.Add("token", getSysinfo().token); HttpResponseMessage response = client.PostAsync(DiagUrl + "/service/getfile", httpContent).Result; String statusCode = response.StatusCode.ToString(); if (response.IsSuccessStatusCode) { byte[] result = response.Content.ReadAsByteArrayAsync().Result; if(result==null || result.Length <=0) { errcall("没有此文件"); return; } String path=ConfigService.ReportDir; if(!Directory.Exists(path)) { Directory.CreateDirectory(path); } path+=appmodel.name+"_"+appmodel.modality+".pdf"; Stream outStream = System.IO.File.Create(path); outStream.Write(result, 0, result.Length); outStream.Flush(); outStream.Close(); success("已保存:\r\n"+path); } else { errcall("获取失败:" + response.StatusCode); } } catch (Exception e) { errcall("访问服务失败: " + e.Message + "\r\n" ); }