(转载请注明来源: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" );
            }
View Code

相关文章:

  • 2022-12-23
  • 2021-11-26
  • 2021-06-29
  • 2021-11-02
  • 2022-01-20
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-04-14
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-12-22
  • 2022-12-23
相关资源
相似解决方案