博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
.NET后台访问其他站点代码整理
阅读量:6080 次
发布时间:2019-06-20

本文共 7529 字,大约阅读时间需要 25 分钟。

HttpWebRequest request = WebRequest.Create(@"http://localhost:8080/mail/SendMail") as HttpWebRequest;        request.Method = "post";        User user = (User)Session["CurrentUser"];        // 拼接成请求参数串,并进行编码,成为字节          string postData = "send=" + send + "©=" + 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
list = new List
(); 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;

 

转载地址:http://neqgx.baihongyu.com/

你可能感兴趣的文章
带着问题去学习--Nginx配置解析(一)
查看>>
onix-文件系统
查看>>
java.io.Serializable浅析
查看>>
我的友情链接
查看>>
多线程之线程池任务管理通用模板
查看>>
CSS3让长单词与URL地址自动换行——word-wrap属性
查看>>
CodeForces 580B Kefa and Company
查看>>
开发规范浅谈
查看>>
Spark Streaming揭秘 Day29 深入理解Spark2.x中的Structured Streaming
查看>>
鼠标增强软件StrokeIt使用方法
查看>>
本地连接linux虚拟机的方法
查看>>
某公司面试java试题之【二】,看看吧,说不定就是你将要做的题
查看>>
BABOK - 企业分析(Enterprise Analysis)概要
查看>>
Linux 配置vnc,开启linux远程桌面
查看>>
NLog文章系列——如何优化日志性能
查看>>
Hadoop安装测试简单记录
查看>>
CentOS6.4关闭触控板
查看>>
ThreadPoolExecutor线程池运行机制分析-线程复用原理
查看>>
React Native 极光推送填坑(ios)
查看>>
Terratest:一个用于自动化基础设施测试的开源Go库
查看>>