用c#保存远程图片时提示"基础连接已经关闭: 无法解析此远程名称。 ",是不是端口被关闭的问题,要开什么端口呢?443吗?

解决方案 »

  1.   

    代码如下:
        //保存远程图片
        public string Get_Img(string a_strUrl,int timeout,string filepath){
         string errmsg;
          try{
            HttpWebRequest myReq = (HttpWebRequest)HttpWebRequest.Create(a_strUrl) ;
            myReq.Timeout = timeout;
    HttpWebResponse HttpWResp = (HttpWebResponse)myReq.GetResponse();         
    Stream myStream = HttpWResp.GetResponseStream () ;          
    Bitmap map = new Bitmap( myStream );
    PictureBox picB = new PictureBox();
    picB.Image = (Image)map;
    string path = filepath.Substring( 0,filepath.LastIndexOf( "\\" ) );
    if (!Directory.Exists(path)){
    //CreateDir( path );
    }               
      picB.Image.Save(filepath);  
      errmsg="ok";              
          }
          catch(Exception exp){
            string ss = exp.Message;
            //WriteLog( filepath.Substring(0,filepath.LastIndexOf("\\")) + "\\error.log",a_strUrl + "--" + ss + "\r\n");        
            errmsg=ss;
    }
    return errmsg;
        }
      

  2.   

    你这样写问题大大的
    b/s是用户发出请求,服务器返回信息。然后这个连接就会断掉,你只能发送个包含图片流的请求给服务器,服务器通过一系列操作后才能保存图像。就像httpfile组件一样