博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
常用方法
阅读量:6234 次
发布时间:2019-06-22

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

1、C#调用URL接口

///         /// 处理中心          ///          ///         /// 路径        /// 账号        /// 公司名        /// 创建时间         ///         /// 大小           ///         public string NoticeToEvidenceHandle(string fileName, string location, string userAccount, string identity, DateTime createTime,            string fileTypeId, string fileUploader, long size)        {            try            {                //{“Appcode”:””,Appkey:””,"FileUploader":"","FileName":"","FileTypeId":"","FileSize":,"UploadTime":"",”Location”:"", “EvidenceCategoryId”:2,”UserAccount”:””, “Identity”:”code”}                //Evidencecategory有1,2,3,7                 StringBuilder jsonNoticeEmlSb = new StringBuilder();                jsonNoticeEmlSb.Append("{
"); jsonNoticeEmlSb.Append("\"AppCode\":\"" + appCode + "\","); jsonNoticeEmlSb.Append("\"AppKey\":\"" + appKey + "\","); jsonNoticeEmlSb.Append("\"FileUploader\":\"" + fileUploader + "\","); jsonNoticeEmlSb.Append("\"FileName\":\"" + fileName + "\","); jsonNoticeEmlSb.Append("\"FileTypeId\":\"" + fileTypeId + "\","); jsonNoticeEmlSb.Append("\"FileSize\":\"" + size + "\","); jsonNoticeEmlSb.Append("\"UploadTime\":\"" + createTime + "\","); jsonNoticeEmlSb.Append("\"Location\":\"" + location + "\","); jsonNoticeEmlSb.Append("\"EvidenceCategoryId\":\"" + evidenceCategoryId + "\","); jsonNoticeEmlSb.Append("\"UserAccount\":\"" + userAccount + "\","); jsonNoticeEmlSb.Append("\"Identity\":\"" + identity + "\","); jsonNoticeEmlSb.Append("}"); string jsonNoticeStr = jsonNoticeEmlSb.ToString(); string evidenceProcessUrl = eventNotice; //LogWriter.Info("证据处理中心-url:{0} json{1}", evidenceProcessUrl, jsonNoticeStr); HttpWebRequest request = (HttpWebRequest)WebRequest.Create(evidenceProcessUrl); request.Method = "POST"; request.ContentType = "application/json;charset=UTF-8"; Stream requestStream = request.GetRequestStream(); byte[] postBytes = Encoding.UTF8.GetBytes(jsonNoticeStr); requestStream.Write(postBytes, 0, postBytes.Length); requestStream.Close(); HttpWebResponse response = (HttpWebResponse)request.GetResponse(); string result; using (StreamReader reader = new StreamReader(response.GetResponseStream())) { result = reader.ReadToEnd(); } if (result != null) { object obj = fastJSON.JSON.Instance.Parse(result); if (obj != null && obj is IDictionary) { IDictionary ctx = obj as IDictionary; if (ctx.Contains("resultMsg")) { if (ctx["resultMsg"].Equals("成功")) { return ctx["resultMsg"].ToString(); } else { return "失败"; } } } } return "失败"; ; } catch (Exception ex) { return "失败"; } }

 

  

2、C#使用126的SMTP服务器发送邮件

public void EmailMessage(string subject, string body, string mailFrom, string mailPwd, string mailTo)        {            MailMessage message = new MailMessage();            message.From = new MailAddress(mailFrom);            message.To.Add(new MailAddress(mailTo));            message.Subject = subject;            message.Body = body;// "

Welcome

This is an HTML message for outofmemory.cn."; message.IsBodyHtml = true; message.BodyEncoding = System.Text.Encoding.UTF8; // Send the message SmtpClient smtpclient = new SmtpClient("smtp.126.com"); smtpclient.DeliveryMethod = SmtpDeliveryMethod.Network; smtpclient.Credentials = new System.Net.NetworkCredential(mailFrom, mailPwd); smtpclient.Send(message); }

调用:

asy.EmailMessage("主题", "

Welcome

This is an HTML message for outofmemory.cn.","发件人邮箱","发件人邮箱密码","收件人邮箱");

 

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

你可能感兴趣的文章
详细解析:如何制作嵌入式Linux文件系统
查看>>
C# 两个独立exe程序直接通信
查看>>
【Unity3d】【项目学习心得】从资源server下载资源(一)
查看>>
C# WinForm 技巧八:界面开发之“WeifenLuo.WinFormsUI.Docking+OutLookBar” 使用
查看>>
Image Wall - jQuery & CSS3 图片墙效果
查看>>
使用ffmepg的lib库调试,debug版本下调试无问题,但release版本会出现跑飞的现象...
查看>>
IOS多线程 总结 -------------核心代码(GCD)
查看>>
SSL连接建立过程分析(1)
查看>>
[CI]CodeIgniter快速开发指南
查看>>
PowerDesigner中创建Oracle表全过程记录
查看>>
mysql中char,varchar,text区别总结
查看>>
宝宝日记
查看>>
Query Designer:Variable 变量
查看>>
python进阶八_警告和异常
查看>>
Tomcat JVM
查看>>
基础才是重中之重~多线程的代价~我的内存都被吃了!
查看>>
学习boost::asio一些小例子
查看>>
[转]Linq 如何实现 in 与 not in
查看>>
怎样修复“Windows/System32/Config/System中文件丢失或损坏”故障
查看>>
C#:控制台程序调用中间库创建窗体
查看>>