贫民窟里的程序高手

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::
HttpWebRequest request = WebRequest.Create(@"http://localhost:8080/mail/SendMail") as HttpWebRequest;

        request.Method = "post";

        User user = (User)Session["CurrentUser"];

        // 拼接成请求参数串,并进行编码,成为字节  
        string postData = "send=" + send + "&copy=" + copy + "&secret=" + secret + "&subject=" + HttpUtility.UrlEncode(this.txtTopic.Text, Encoding.GetEncoding("GBK")) + "&username=" + user.Email + "&pass=" + user.MailPwd + "&content=" + HttpUtility.UrlEncode(this.ftbContent.Text, Encoding.GetEncoding("GBK"));
        ASCIIEncoding encoding = new ASCIIEncoding();
        byte[] byte1 = encoding.GetBytes(postData);
        // 设置请求的参数形式  
        request.ContentType = "application/x-www-form-urlencoded";
        request.Headers.Add("content", "text/html; charset=gbk");

        // 设置请求参数的长度.  
        request.ContentLength = byte1.Length;

        // 取得发向服务器的流  
        System.IO.Stream newStream = request.GetRequestStream();

        // 使用 POST 方法请求的时候,实际的参数通过请求的 Body 部分以流的形式传送  
        newStream.Write(byte1, 0, byte1.Length);

        // 完成后,关闭请求流.  
        newStream.Close();

        HttpWebResponse response = (HttpWebResponse)request.GetResponse();

        // 然后可以得到以流的形式表示的回应内容  
        System.IO.Stream receiveStream
            = response.GetResponseStream();

        // 还可以将字节流包装为高级的字符流,以便于读取文本内容   
        // 需要注意编码  
        System.IO.StreamReader readStream
            = new System.IO.StreamReader(receiveStream, Encoding.GetEncoding("GB2312"));

        string res = readStream.ReadToEnd();

        // 完成后要关闭字符流,字符流底层的字节流将会自动关闭  
        response.Close();
        readStream.Close();

 

HttpWebRequest req = HttpWebRequest.Create(@"http://localhost:8080/mail/getmail.jsp") as HttpWebRequest;

        req.Method = "post";

        User user = (User)Session["CurrentUser"];
        // 拼接成请求参数串,并进行编码,成为字节  
        string postData = "page=" + PageNor + "&username=" + user.Email + "&pass=" + user.MailPwd;
        ASCIIEncoding encoding = new ASCIIEncoding();
        byte[] byte1 = encoding.GetBytes(postData);
        // 设置请求的参数形式  
        req.ContentType = "application/x-www-form-urlencoded";

        // 设置请求参数的长度.  
        req.ContentLength = byte1.Length;

        // 取得发向服务器的流  
        System.IO.Stream newStream = req.GetRequestStream();

        // 使用 POST 方法请求的时候,实际的参数通过请求的 Body 部分以流的形式传送  
        newStream.Write(byte1, 0, byte1.Length);

        // 完成后,关闭请求流.  
        newStream.Close();

        HttpWebResponse response = (HttpWebResponse)req.GetResponse();

        // 然后可以得到以流的形式表示的回应内容  
        System.IO.Stream receiveStream
            = response.GetResponseStream();

        // 还可以将字节流包装为高级的字符流,以便于读取文本内容   
        // 需要注意编码  
        System.IO.StreamReader readStream
            = new System.IO.StreamReader(receiveStream, Encoding.GetEncoding("GB2312"));

        string res = readStream.ReadToEnd();

        // 完成后要关闭字符流,字符流底层的字节流将会自动关闭  
        response.Close();
        readStream.Close();

        if (!res.Equals("0")) 
        {
            DataTable dt = new DataTable();
            dt.Columns.Add("id");
            dt.Columns.Add("subject");
            dt.Columns.Add("sender");
            dt.Columns.Add("date");
            string[] ss = res.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries);
            foreach (string s in ss)
            {
                DataRow dr = dt.NewRow();
                string[] str = s.Split(new char[] { '&' }, StringSplitOptions.RemoveEmptyEntries);
                dr["id"] = str[0];
                dr["subject"] = str[3];
                dr["sender"] = str[1];
                dr["date"] = DateTime.Parse(str[5]);
                dt.Rows.Add(dr);
            }

            int totalCount = 0;
            User curUser = (User)Session["CurrentUser"];
            int isDelete = 0;

            DataTable dt1 = SendProcessManager.GetSendAffairsByProc(curUser.ID, isDelete, PageNor, CommonInfo.PageSize, ref totalCount);
            if (totalCount > 0 && dt != null && dt.Rows.Count == 0)
            {
                PageNor--;
                dt1 = SendProcessManager.GetSendAffairsByProc(curUser.ID, isDelete, PageNor, CommonInfo.PageSize, ref totalCount);
            }

            List<MessageModel> list = new List<MessageModel>();

            foreach (DataRow dr in dt.Rows) 
            {
                MessageModel mm = new MessageModel();
                mm.Id = dr["id"].ToString();
                mm.Subject = dr["subject"].ToString();
                mm.Sender = dr["sender"].ToString();
                mm.Date = DateTime.Parse(dr["date"].ToString());
                mm.Status = "2";

                list.Add(mm);
            }

            foreach (DataRow dr in dt1.Rows) 
            {
                MessageModel mm = new MessageModel();
                mm.Id = dr["INFOID"].ToString();
                mm.CurLevel = dr["CurLevel"].ToString();
                mm.UesrID = dr["UserID"].ToString();
                mm.Date = DateTime.Parse(dr["SENDTIME"].ToString());
                mm.Subject = dr["Topic"].ToString();
                mm.AnnexCount = dr["AnnexCount"].ToString();
                mm.ReadStatus = dr["ReadStatus"].ToString();
                mm.Position = dr["Position"].ToString();
                mm.Sender = dr["UserName"].ToString();
                mm.RelateUserID = dr["RelateUserID"].ToString();
                mm.InfoTableType = dr["InfoTableType"].ToString();
                mm.Level = dr["Level"].ToString();
                mm.Status = "1";

                list.Add(mm);
            }

            var m = from l in list orderby l.Date descending select l;

            this.gvAffairs.DataSource = m;
            this.gvAffairs.DataBind();
HttpWebRequest request = WebRequest.Create(@"http://localhost:8080/mail/maildetail.jsp") as HttpWebRequest;

            request.Method = "post";

            // 拼接成请求参数串,并进行编码,成为字节  
            string postData = "id=" + this.hfAffairId.Value + "&username=" + this.username + "&pass=" + this.pass;
            ASCIIEncoding encoding = new ASCIIEncoding();
            byte[] byte1 = encoding.GetBytes(postData);
            // 设置请求的参数形式  
            request.ContentType = "application/x-www-form-urlencoded";

            // 设置请求参数的长度.  
            request.ContentLength = byte1.Length;

            // 取得发向服务器的流  
            System.IO.Stream newStream = request.GetRequestStream();

            // 使用 POST 方法请求的时候,实际的参数通过请求的 Body 部分以流的形式传送  
            newStream.Write(byte1, 0, byte1.Length);

            // 完成后,关闭请求流.  
            newStream.Close();

            HttpWebResponse response = (HttpWebResponse)request.GetResponse();

            // 然后可以得到以流的形式表示的回应内容  
            System.IO.Stream receiveStream
                = response.GetResponseStream();

            // 还可以将字节流包装为高级的字符流,以便于读取文本内容   
            // 需要注意编码  
            System.IO.StreamReader readStream
                = new System.IO.StreamReader(receiveStream, Encoding.GetEncoding("GB2312"));

            string res = readStream.ReadToEnd();

            // 完成后要关闭字符流,字符流底层的字节流将会自动关闭  
            response.Close();
            readStream.Close();

            string[] ss = res.Split(new string[] { "&#@" }, StringSplitOptions.RemoveEmptyEntries);

            this.hfAffairId.Value = ss[0];
            this.lblTopic.Text = ss[1];
            this.lblContents.Text = ss[4];
            this.lblCreateUser.Text = ss[2];
            this.lblBeginAffairTime.Text = DateTime.Parse(ss[3]).ToString("yyyy-MM-dd HH:mm:ss");
            this.flowTr.Style.Add("display", "none");
            this.sendTr.Style.Add("display", "");
            this.lblSend.Text = ((User)Session["CurrentUser"]).Email;

 

posted on 2014-04-25 13:42  贫民窟里的程序高手  阅读(457)  评论(0编辑  收藏  举报