zoukankan      html  css  js  c++  java
  • 常用方法

    1、C#调用URL接口

      /// <summary>
            /// 处理中心  
            /// </summary> 
            /// <param name="fileName"></param>
            /// <param name="location">路径</param>
            /// <param name="userAccount">账号</param>
            /// <param name="identity">公司名</param>
            /// <param name="createTime">创建时间</param> 
            /// <param name="fileUploader"></param>
            /// <param name="size">大小</param>   
            /// <param name="fileTypeId"></param>
            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;// "<html><body><h1>Welcome</h1><br>This is an HTML message for outofmemory.cn.</body></html>";
                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("主题", "<html><body><h1>Welcome</h1><br>This is an HTML message for outofmemory.cn.</body></html>","发件人邮箱","发件人邮箱密码","收件人邮箱");
                
  • 相关阅读:
    [转]Windows visio2019破解激活
    KMP模式匹配算法
    【蓝桥杯2016_C++】t3:方格填数
    【蓝桥杯2015_C++】t4:格子中输出
    【蓝桥杯2015_C++】t3:奇妙的数字
    【蓝桥杯2014_C++】t6:扑克序列
    【蓝桥杯2014_C++】t4:史丰收速算
    【蓝桥杯2014_C++】t3:神奇算式
    【蓝桥杯2017_C++】t1:迷宫
    【蓝桥杯】买不到的数目
  • 原文地址:https://www.cnblogs.com/PEPE/p/4512002.html
Copyright © 2011-2022 走看看