HttpHelper类及调用

首先列出HttpHelper类

/// <summary>
    /// Http操作类
    /// </summary>
    public class HttpHelper
    {
        private static log4net.ILog mLog = log4net.LogManager.GetLogger("HttpHelper");

        [DllImport("wininet.dll", CharSet = CharSet.Auto, SetLastError = true)]
        public static extern bool InternetSetCookie(string lpszUrlName, string lbszCookieName, string lpszCookieData);

        [DllImport("wininet.dll", CharSet = CharSet.Auto, SetLastError = true)]
        public static extern bool InternetGetCookie(string lpszUrlName, string lbszCookieName, StringBuilder lpszCookieData, ref int lpdwSize);
        public static StreamReader mLastResponseStream = null;
        public static System.IO.StreamReader LastResponseStream
        {
            get { return mLastResponseStream; }
        }
        private static CookieContainer mCookie = null;
        public static CookieContainer Cookie
        {
            get { return mCookie; }
            set { mCookie = value; }
        }
        private static CookieContainer mLastCookie = null;
        public static HttpWebRequest CreateWebRequest(string url, HttpRequestType httpType, string contentType, string data, Encoding requestEncoding, int timeout, bool keepAlive)
        {
            if (String.IsNullOrWhiteSpace(url))
            {
                throw new Exception("URL为空");
            }
            HttpWebRequest webRequest = null;
            Stream requestStream = null;
            byte[] datas = null;
            switch (httpType)
            {
                case HttpRequestType.GET:
                case HttpRequestType.DELETE:
                    if (!String.IsNullOrWhiteSpace(data))
                    {
                        if (!url.Contains(‘?‘))
                        {
                            url += "?" + data;
                        }
                        else url += "&" + data;
                    }
                    if(url.StartsWith("https:"))
                    {
                        System.Net.ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls11 | SecurityProtocolType.Tls12;
                        ServicePointManager.ServerCertificateValidationCallback = new System.Net.Security.RemoteCertificateValidationCallback(CheckValidationResult);
                    }
                    webRequest = (HttpWebRequest)WebRequest.Create(url);
                    webRequest.Method = Enum.GetName(typeof(HttpRequestType), httpType);
                    if (contentType != null)
                    {
                        webRequest.ContentType = contentType;
                    }
                    if (mCookie == null)
                    {
                        webRequest.CookieContainer = new CookieContainer();
                    }
                    else
                    {
                        webRequest.CookieContainer = mCookie;
                    }
                    if (keepAlive)
                    {
                        webRequest.KeepAlive = keepAlive;
                        webRequest.ReadWriteTimeout = timeout;
                        webRequest.Timeout = 60000;
                        mLog.Info("请求超时时间..." + timeout);
                    }
                    break;
                default:
                    if (url.StartsWith("https:"))
                    {
                        System.Net.ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls11 | SecurityProtocolType.Tls12;
                        ServicePointManager.ServerCertificateValidationCallback = new System.Net.Security.RemoteCertificateValidationCallback(CheckValidationResult);
                    }
                    webRequest = (HttpWebRequest)WebRequest.Create(url);
                    webRequest.Method = Enum.GetName(typeof(HttpRequestType), httpType);
                    if (contentType != null)
                    {
                        webRequest.ContentType = contentType;
                    }
                    if (mCookie == null)
                    {
                        webRequest.CookieContainer = new CookieContainer();
                    }
                    else
                    {
                        webRequest.CookieContainer = mCookie;
                    }
                    if (keepAlive)
                    {
                        webRequest.KeepAlive = keepAlive;
                        webRequest.ReadWriteTimeout = timeout;
                        webRequest.Timeout = 60000;
                        mLog.Info("请求超时时间..." + timeout);
                    }
                    if (!String.IsNullOrWhiteSpace(data))
                    {
                        datas = requestEncoding.GetBytes(data);
                    }
                    if (datas != null)
                    {
                        webRequest.ContentLength = datas.Length;
                        requestStream = webRequest.GetRequestStream();
                        requestStream.Write(datas, 0, datas.Length);
                        requestStream.Flush();
                        requestStream.Close();
                    }
                    break;
            }
            //mLog.InfoFormat("请求 Url:{0},HttpRequestType:{1},contentType:{2},data:{3}", url, Enum.GetName(typeof(HttpRequestType), httpType), contentType, data);
            return webRequest;
        }
        public static CookieContainer GetLastCookie()
        {
            return mLastCookie;
        }
        /// <summary>
        /// 设置HTTP的Cookie,以后发送和请求用此Cookie
        /// </summary>
        /// <param name="cookie">CookieContainer</param>
        public static void SetHttpCookie(CookieContainer cookie)
        {
            mCookie = cookie;
        }
        private static HttpWebRequest mLastAsyncRequest = null;
        public static HttpWebRequest LastAsyncRequest
        {
            get { return mLastAsyncRequest; }
            set { mLastAsyncRequest = value; }
        }
        /// <summary>
        /// 发送请求
        /// </summary>
        /// <param name="url">请求Url</param>
        /// <param name="httpType">请求类型</param>
        /// <param name="contentType">contentType:application/x-www-form-urlencoded</param>
        /// <param name="data">请求数据</param>
        /// <param name="encoding">请求数据传输时编码格式</param>
        /// <returns>返回请求结果</returns>
        public static string SendRequest(string url, HttpRequestType httpType, string contentType, string data, Encoding requestEncoding, Encoding reponseEncoding, params AsyncCallback[] callBack)
        {

            int timeout = 0;
            bool keepAlive = false;
            if (callBack != null && callBack.Length > 0 && callBack[0] != null)
            {
                keepAlive = true;
                timeout = 1000*60*60;
                mLog.Info("写入读取超时时间..." + timeout);
            }
           // mLog.Info("开始创建请求....");
            HttpWebRequest webRequest = CreateWebRequest(url, httpType, contentType, data, requestEncoding,timeout,keepAlive);
            string ret = null;
           // mLog.Info("创建请求结束....");
            if (callBack != null && callBack.Length > 0 && callBack[0] != null)
            {
               // mLog.Info("开始异步请求....");
                mLastAsyncRequest = webRequest;
                webRequest.BeginGetResponse(callBack[0], webRequest);
            }
            else
            {
               // mLog.Info("开始同步请求....");
                StreamReader sr = new StreamReader(webRequest.GetResponse().GetResponseStream(), reponseEncoding);
                ret = sr.ReadToEnd();
                sr.Close();
            }
            mLastCookie = webRequest.CookieContainer;
            //mLog.InfoFormat("结束请求 Url:{0},HttpRequestType:{1},contentType:{2},结果:{3}", url, Enum.GetName(typeof(HttpRequestType), httpType), contentType,ret);
            return ret;
        }

        /// <summary>
        /// Http上传文件
        /// </summary>
        public static string HttpUploadFile(string url, string path)
        {
            using (FileStream fs = new FileStream(path, FileMode.Open, FileAccess.Read))
            {
                // 设置参数
                HttpWebRequest request = WebRequest.Create(url) as HttpWebRequest;
                CookieContainer cookieContainer = new CookieContainer();
                request.CookieContainer = cookieContainer;
                request.AllowAutoRedirect = true;
                request.AllowWriteStreamBuffering = false;
                request.SendChunked = true;
                request.Method = "POST";
                request.Timeout = 300000;

                string boundary = DateTime.Now.Ticks.ToString("X"); // 随机分隔线
                request.ContentType = "multipart/form-data;charset=utf-8;boundary=" + boundary;
                byte[] itemBoundaryBytes = Encoding.UTF8.GetBytes("\r\n--" + boundary + "\r\n");
                byte[] endBoundaryBytes = Encoding.UTF8.GetBytes("\r\n--" + boundary + "--\r\n");
                int pos = path.LastIndexOf("\\");
                string fileName = path.Substring(pos + 1);

                //请求头部信息
                StringBuilder sbHeader = new StringBuilder(string.Format("Content-Disposition:form-data;name=\"file\";filename=\"{0}\"\r\nContent-Type:application/octet-stream\r\n\r\n", fileName));
                byte[] postHeaderBytes = Encoding.UTF8.GetBytes(sbHeader.ToString());
                request.ContentLength = itemBoundaryBytes.Length + postHeaderBytes.Length + fs.Length + endBoundaryBytes.Length;
                using (Stream postStream = request.GetRequestStream())
                {
                    postStream.Write(itemBoundaryBytes, 0, itemBoundaryBytes.Length);
                    postStream.Write(postHeaderBytes, 0, postHeaderBytes.Length);
                    int bytesRead = 0;

                    int arrayLeng = fs.Length <= 4096 ? (int)fs.Length : 4096;
                    byte[] bArr = new byte[arrayLeng];
                    int counter = 0;
                    while ((bytesRead = fs.Read(bArr, 0, arrayLeng)) != 0)
                    {
                        counter++;
                        postStream.Write(bArr, 0, bytesRead);
                    }
                    postStream.Write(endBoundaryBytes, 0, endBoundaryBytes.Length);
                }

                //发送请求并获取相应回应数据
                using (HttpWebResponse response = request.GetResponse() as HttpWebResponse)
                {
                    //直到request.GetResponse()程序才开始向目标网页发送Post请求
                    using (Stream instream = response.GetResponseStream())
                    {
                        StreamReader sr = new StreamReader(instream, Encoding.UTF8);
                        //返回结果网页(html)代码
                        string content = sr.ReadToEnd();
                        return content;
                    }
                }
            }
        }

        public static string HttpUploadFile(string url, MemoryStream files, string fileName)
        {
            using (MemoryStream fs = files)
            {
                // 设置参数
                HttpWebRequest request = WebRequest.Create(url) as HttpWebRequest;
                CookieContainer cookieContainer = new CookieContainer();
                request.CookieContainer = cookieContainer;
                request.AllowAutoRedirect = true;
                request.AllowWriteStreamBuffering = false;
                request.SendChunked = true;
                request.Method = "POST";
                request.Timeout = 300000;

                string boundary = DateTime.Now.Ticks.ToString("X"); // 随机分隔线
                request.ContentType = "multipart/form-data;charset=utf-8;boundary=" + boundary;
                byte[] itemBoundaryBytes = Encoding.UTF8.GetBytes("\r\n--" + boundary + "\r\n");
                byte[] endBoundaryBytes = Encoding.UTF8.GetBytes("\r\n--" + boundary + "--\r\n");

                //请求头部信息
                StringBuilder sbHeader = new StringBuilder(string.Format("Content-Disposition:form-data;name=\"file\";filename=\"{0}\"\r\nContent-Type:application/octet-stream\r\n\r\n", fileName));
                byte[] postHeaderBytes = Encoding.UTF8.GetBytes(sbHeader.ToString());
                request.ContentLength = itemBoundaryBytes.Length + postHeaderBytes.Length + fs.Length + endBoundaryBytes.Length;
                using (Stream postStream = request.GetRequestStream())
                {
                    postStream.Write(itemBoundaryBytes, 0, itemBoundaryBytes.Length);
                    postStream.Write(postHeaderBytes, 0, postHeaderBytes.Length);
                    int bytesRead = 0;

                    int arrayLeng = fs.Length <= 4096 ? (int)fs.Length : 4096;
                    byte[] bArr = new byte[arrayLeng];
                    int counter = 0;
                    fs.Position = 0;
                    while ((bytesRead = fs.Read(bArr, 0, arrayLeng)) != 0)
                    {
                        counter++;
                        postStream.Write(bArr, 0, bytesRead);
                    }
                    postStream.Write(endBoundaryBytes, 0, endBoundaryBytes.Length);
                }

                //发送请求并获取相应回应数据
                using (HttpWebResponse response = request.GetResponse() as HttpWebResponse)
                {
                    //直到request.GetResponse()程序才开始向目标网页发送Post请求
                    using (Stream instream = response.GetResponseStream())
                    {
                        StreamReader sr = new StreamReader(instream, Encoding.UTF8);
                        //返回结果网页(html)代码
                        string content = sr.ReadToEnd();
                        return content;
                    }
                }
            }
        }

        #region public static 方法

        /// <summary>
        /// 将请求的流转化为字符串
        /// </summary>
        /// <param name="info"></param>
        /// <returns></returns>
        public static string GetStr(Stream info)
        {
            string result = "";
            try
            {
                using (StreamReader sr = new StreamReader(info, System.Text.Encoding.UTF8))
                {
                    result = sr.ReadToEnd();
                    sr.Close();
                }
            }
            catch
            {
            }
            return result;
        }

        /// <summary>
        /// 参数转码
        /// </summary>
        /// <param name="str"></param>
        /// <returns></returns>
        public static string stringDecode(string str)
        {
            return HttpUtility.UrlDecode(HttpUtility.UrlDecode(str, System.Text.Encoding.GetEncoding("UTF-8")), System.Text.Encoding.GetEncoding("UTF-8"));
        }

        /// <summary>
        /// json反序列化
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="json"></param>
        /// <returns></returns>
        public static T Deserialize<T>(string json)
        {
            try
            {
                T obj = Activator.CreateInstance<T>();
                using (MemoryStream ms = new MemoryStream(System.Text.Encoding.UTF8.GetBytes(json)))
                {
                    DataContractJsonSerializer serializer = new DataContractJsonSerializer(obj.GetType());
                    return (T)serializer.ReadObject(ms);
                }
            }
            catch
            {
                return default(T);
            }
        }

        #endregion

        public static bool CheckValidationResult(object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors)
        {   // 总是接受
            return true;
        }

    }
    public enum HttpRequestType
    {
        POST,
        GET,
        DELETE,
        PUT,
        PATCH,
        HEAD,
        TRACE,
        OPTIONS
    }

然后列出HttpHelper的调用

1、不带参数调用

public bool ConnectServer()
        {
            try
            {
                string url = "https://i.cnblogs.com";

                string xml = HttpHelper.SendRequest(url, HttpRequestType.POST, null, null, Encoding.UTF8, Encoding.UTF8);
                NormalResponse nr = HuaweiXMLHelper.GetNormalResponse(xml);
                if (nr.Code == "0")
                {
HttpHelper.SetHttpCookie(HttpHelper.GetLastCookie());
                    mIsConnect = true;
                    return true;
                }
                else
                {
                    mIsConnect = false;
                    return false;
                }
            }
            catch (System.Exception ex)
            {
                mIsConnect = false;
                return false;
            }
        }

2.带参数调用

private bool HandleIntelligentTask(string taskId,bool bStop)
        {
            try
            {
                if (!mIsConnect)
                {
                    return false;
                }
                StringBuilder sb = new StringBuilder();
                sb.AppendFormat("<request>\r\n");
                sb.AppendFormat("<task_id>{0}</task_id>\r\n", taskId);//<!-- task-id为调用方生成的UUID或其它串 -->
                sb.AppendFormat("<status>{0}</status>\r\n",bStop?0:1);
                sb.AppendFormat("</request>\r\n");
                string xml = sb.ToString();
                string url = mIAServerUrl + "/sdk_service/rest/video-analysis/handle-intelligent-analysis";
                string xml2 = HttpHelper.SendRequest(url, HttpRequestType.POST, "text/plain;charset=utf-8", xml, Encoding.UTF8, Encoding.UTF8);
                NormalResponse nr = HuaweiXMLHelper.GetNormalResponse(xml2);
                if (nr.Code == "0")
                {
                    return true;
                }
                else
                {
                    return false;
                }
            }
            catch (System.Exception ex)
            {
                return false;
            }

        }

3.异步调用

private void ReStartAlarmServer(List<string> list, string alarmUrl, Thread[] listThread)
        {
            StopAlarm(alarmUrl, listThread);
            listThread[0]= new Thread(new ThreadStart(delegate()
                        {
                            try
                            {
                                if (!mIsConnect)
                                {
                                    mLog.Error("未登录!--ReStartAlarmServer-结束!");
                                    return;
                                }
                                mLog.Info("ReStartAlarmServer开始报警连接....");
                                if (String.IsNullOrWhiteSpace(alarmUrl)) return;
                                mLog.InfoFormat("ReStartAlarmServer请求报警:URL={0}", alarmUrl);
                                string xml = "task-id=0";
                                string xml2 = HttpHelper.SendRequest(alarmUrl, HttpRequestType.POST, "application/x-www-form-urlencoded", xml, Encoding.UTF8, Encoding.UTF8, AlarmCallBack);
                                mLog.Info("ReStartAlarmServer报警连接成功!");
                            }
                            catch (System.Threading.ThreadAbortException ex)
                            {
                                mLog.Info("ReStartAlarmServer线程已人为终止!" + ex.Message, ex);
                            }
                            catch (System.Exception ex)
                            {
                                mLog.Error("ReStartAlarmServer开始报警连接失败:" + ex.Message, ex);
                                mLog.Info("ReStartAlarmServer开始重新报警连接....");
                                mTimes = 50;
                            }
                            finally
                            {

                            }
                        }));
            listThread[0].IsBackground = true;
            listThread[0].Start();
        }
        private void AlarmCallBack(IAsyncResult ir)
        {
            try
            {
                HttpWebRequest webRequest = (HttpWebRequest)ir.AsyncState;
                string salarmUrl = webRequest.Address.OriginalString;
                Thread[] alarmThead = dicAlarmUrls[salarmUrl];
                HttpWebResponse response = (HttpWebResponse)webRequest.EndGetResponse(ir);
                Stream stream = response.GetResponseStream();
               alarmThead[1]=  new Thread(new ThreadStart(delegate()
                {
                    try
                    {
                        byte[] buffer = new byte[mAlarmReadCount];
                        int count = 0;
                        string strMsg = "";
                        int startIndex = -1;
                        int endIndex = -1;

                        NormalResponse res = null;
                        DateTime dtStart = DateTime.Now;
                        DateTime dtEnd = DateTime.Now;
                        while (!mIsCloseAlarm)
                        {
                            count = stream.Read(buffer, 0, mAlarmReadCount);
                            if (count > 0)
                            {
                                strMsg += Encoding.UTF8.GetString(buffer, 0, count);
                                startIndex = strMsg.IndexOf("<response>");
                                endIndex = strMsg.IndexOf("</response>");
                                string xml = strMsg.Substring(startIndex, endIndex - startIndex + "</response>".Length);
                                res = HuaweiXMLHelper.GetNormalResponse(xml);
                                strMsg = strMsg.Substring(endIndex + "</response>".Length);
                                startIndex = -1;
                                endIndex = -1;
                                break;
                            }
                            dtEnd = DateTime.Now;
                            if ((dtEnd - dtStart).TotalSeconds > 10)
                            {
                                throw new Exception("连接信息未有获取到,需要重启报警!");
                            }
                        }
                        while (!mIsCloseAlarm)
                        {
                            count = stream.Read(buffer, 0, mAlarmReadCount);
                            if (count > 0)
                            {
                                string temp = Encoding.UTF8.GetString(buffer, 0, count);
                                strMsg += temp;
                                while (strMsg.Length > 0)
                                {
                                    if (startIndex == -1)//未发现第一个<task-info>
                                    {
                                        startIndex = strMsg.IndexOf("<task-info>");
                                        if (startIndex == -1)
                                        {
                                            if (strMsg.Length >= "<task-info>".Length)
                                            {
                                                strMsg = strMsg.Substring(strMsg.Length - "<task-info>".Length);
                                            }
                                            break;
                                        }
                                    }
                                    if (startIndex >= 0)
                                    {
                                        int i = startIndex + "<task-info>".Length;
                                        int taskInfoEndIndex = strMsg.IndexOf("</task-info>", i);
                                        if (taskInfoEndIndex > 0)//必须有任务结束节点
                                        {
                                            i = taskInfoEndIndex + "</task-info>".Length;
                                            int i1 = strMsg.IndexOf("</attach-rules>", i);//找到轨迹节点结束
                                            int i2 = strMsg.IndexOf("</alarm>", i);//找到报警节点结束,发现一条报警
                                            if (i1 == -1 && i2 == -1)//没有标志结束
                                            {
                                                break;
                                            }
                                            else if (i1 >= 0 && (i1 < i2 || i2 == -1))//找到轨迹结束节点
                                            {
                                                strMsg = strMsg.Substring(i1 + "</attach-rules>".Length);
                                                startIndex = -1;
                                                endIndex = -1;
                                                continue;
                                            }
                                            else if (i2 > 0 && (i2 < i1 || i1 == -1))//找报警节点
                                            {
                                                endIndex = i2;//找到报警节点结束,发现一条报警
                                                string alarmXml = "<taskalarm>" + strMsg.Substring(startIndex, endIndex - startIndex + "</alarm>".Length) + "</taskalarm>";

                                                Thread th = new Thread(new ThreadStart(delegate()
                                                {
                                                    ParseAlarmXml(alarmXml);
                                                }));
                                                th.IsBackground = true;
                                                th.Start();

                                                strMsg = strMsg.Substring(endIndex + "</alarm>".Length);
                                                startIndex = -1;
                                                endIndex = -1;
                                                continue;
                                            }
                                        }
                                        else
                                        {
                                            break;
                                        }
                                    }
                                }
                            }
                            else
                            {
                                Console.WriteLine("##########读取报警反馈:无");
                                Thread.Sleep(1000);
                            }
                        }
                    }
                    catch (System.Threading.ThreadAbortException ex)
                    {
                        mLog.Info("AlarmCallBack...7");
                        try
                        {
                            if (stream != null)
                            {
                                stream.Close();
                                stream.Dispose();
                                response.Close();
                            }
                        }
                        catch
                        {
                        }
                        mLog.Info("AlarmCallBack线程已人为终止!--0" + ex.Message, ex);
                    }
                    catch(IOException ex)
                    {
                        mLog.Info("AlarmCallBack...8");
                        try
                        {
                            if (stream != null)
                            {
                                stream.Close();
                                stream.Dispose();
                                response.Close();
                            }
                        }
                        catch
                        {
                        }
                    }
                    catch (ObjectDisposedException ex)
                    {
                        mLog.Info("AlarmCallBack...9");
                        mLog.Info("AlarmCallBack读取流已人为终止!--2" + ex.Message, ex);
                        try
                        {
                            if (stream != null)
                            {
                                stream.Close();
                                stream.Dispose();
                                response.Close();
                            }
                        }
                        catch
                        {
                        }
                    }
                    catch (System.Exception ex)
                    {
                        mLog.Info("AlarmCallBack...10");
                          mLog.Error("AlarmCallBack 0:" + ex.Message,ex);
                          try
                          {
                              if (stream != null)
                              {
                                  stream.Close();
                                  stream.Dispose();
                                  response.Close();
                              }
                          }
                          catch
                          {
                          }

                    }
                    finally
                    {

                    }
                }));
               alarmThead[1].IsBackground = true;
               alarmThead[1].Start();

            }
            catch (System.Exception ex)
            {
                mLog.Info("AlarmCallBack...11");
                mLog.Error("AlarmCallBack 1:" + ex.Message,ex);
                mLog.Info("AlarmCallBack开始重新报警连接....3");
                mTimes = 50;
            }
            finally
            {

            }
        }

以上就是简单的HttpHelper类的方法使用

时间: 2024-11-08 23:19:03

HttpHelper类及调用的相关文章

json类 方便调用

jsonutil类 1 package *********** 2 3 import java.lang.reflect.Field; 4 import java.lang.reflect.Type; 5 import java.util.ArrayList; 6 import java.util.HashMap; 7 import java.util.Iterator; 8 import java.util.List; 9 import java.util.Map; 10 11 import

java类中调用servlet

一.Java中调用servlet说明: 我们有时可能需要在Java类中调用Servlet从而实现某些特殊的功能,在JavaAPI中提供了一个URL的类,其中openStream( )方法可以打开URL的连接,并返回一个用于该连接读入的InputStream. 二.Java中调用servlet应用举例: package com.solid.test; import java.io.BufferedReader; import java.io.IOException; import java.io.

HttpWebRequest 模拟登录响应点击事件(开源自己用的HttpHelper类)

平时也经常采集网站数据,也做模拟登录,但一般都是html控件POST到页面登录:还没有遇到用户服务器控件button按钮点击事件登录的,今天像往常一样POST传递参数,但怎么都能登录不了:最后发现还有两个参数需要传,__EVENTVALIDATION和__VIEWSTATE 在传的过程中需要对参数值进行URL编码 System.Web.HttpUtility.UrlEncode(value) 模拟登录代码:在本地写的一个测试的网站来模拟登录,原理都一样: Request request = ne

MFC中如何在一个类中调用另一个类的控件

学习记录: 两个类,一个为主类 1个为:CCkDlg,主类 1个为: Https,用来做HTTPS请求获得页面状态. 测试界面如下: CCkDlg 类里定义函数 void CCkDlg::printf_r(CString str) //用于输出日志信息 { m_log.SetSel(-1,-1); m_log.ReplaceSel(str + "\r\n",1); } Https 类里: #pragma once class CCkDlg; //集成cckDlg class Https

spring管理的类如何调用非spring管理的类

spring管理的类如何调用非spring管理的类. 就是使用一个spring提供的感知概念,在容器启动的时候,注入上下文即可. 下面是一个工具类. 1 import org.springframework.beans.BeansException; 2 import org.springframework.context.ApplicationContext; 3 import org.springframework.context.ApplicationContextAware; 4 imp

HttpHelper类

/// <summary> /// 类说明:HttpHelper类,用来实现Http访问,Post或者Get方式的,直接访问,带Cookie的,带证书的等方式,可以设置代理 /// 重要提示:请不要自行修改本类,如果因为你自己修改后将无法升级到新版本.如果确实有什么问题请到官方网站提建议, /// 我们一定会及时修改 /// 编码日期:2011-09-20 /// 编 码 人:苏飞 /// 联系方式:361983679 /// 官方网址:http://www.sufeinet.com/thre

【从零之三(更)】自定义类中调用讯飞语音包错误解决办法

原文:http://blog.csdn.net/monkeyduck/article/details/24302655 在科大讯飞语音包的Mscdemo中它的方法都是写在Activity中的,这样其实并不是很好,因为Activity只是负责UI交互的,如果项目很简单自然可以,但是一旦比较复杂肯定要自己定义很多包很多类,但是写在Activity中的方法就不能被自己定义的类调用了,咋办尼,那就把方法写在自己的类里就行了.准备工作:把Msc.jar包和libmsc.so拷贝到自己工程的libs目录下,

thinkphp类的调用

1.在controller下新建一个类,类的名称必须按照tp的规范来写. 2.在需要调用的类中,只需new一下被调用的类名. 1 $t=new DataController(); 2 $t->m(); thinkphp类的调用

UI自动化测试4-公共类和调用

1. 作业解答 上节课给大家的作业是find element by.cssSelector. 我简单举一个例子 WebElement email = driver.findElement(By.cssSelector("#emailLink.ccNoUnderline"));email.click();2. 加点小知识a>浏览器窗口最大化WebDriver driver = new ChromeDriver();driver.manage().window().maximize(