예제 #1
0
        /// <summary>
        /// 提交一个字符串到指定路径
        /// </summary>
        /// <param name="url">提交的地址</param>
        /// <param name="type">提交的类型</param>
        /// <param name="message">提交的信息</param>
        /// <returns>提交返回的信息</returns>
        public static string Submit(string url, SubmitType type, string message)
        {
            string result = string.Empty;

            System.Net.WebClient WebClientObj = new System.Net.WebClient();
            try
            {
                result = WebClientObj.UploadString(url, type.ToString(), message);
                WebClientObj.Dispose();
            }
            catch
            {
                //throw ex;
            }
            finally
            {
                WebClientObj.Dispose();
            }

            return(result);
        }
예제 #2
0
        /// <summary>
        /// 模拟表单提交
        /// </summary>
        /// <param name="url">提交的路径</param>
        /// <param name="type">提交的类型</param>
        /// <param name="keyValue">表单中的键值对</param>
        /// <returns></returns>
        public static string Submit(string url, SubmitType type, NameValueCollection keyValue)
        {
            string result = string.Empty;

            System.Net.WebClient WebClientObj = new System.Net.WebClient();
            try
            {
                byte[] byRemoteInfo = WebClientObj.UploadValues(url, type.ToString(), keyValue);

                //下面都没用啦,就上面一句话就可以了
                string sRemoteInfo = System.Text.Encoding.UTF8.GetString(byRemoteInfo);
                //这是获取返回信息
                result = sRemoteInfo;
            }
            catch
            {
                //throw ex;
            }
            finally
            {
                WebClientObj.Dispose();
            }
            return(result);
        }