首页 | 站长免费中心 | 新手上路 | 网站运营 | 网页制作 | 图片设计 | 动画设计 | 网页编程 | 网页特效 | 本站专题 | 虚拟主机 | 域名注册 | 网站建设 | 程序下载
       免费空间资源 | 新闻咨询 | 免费域名 | 免费网盘 | 网站推广 | 网站策划 | 建站经验 | 网站优化 | 网页代码 | 源码下载 | 音乐小偷 | 网络赚钱 | 论坛交流
网站建设
网站建设
虚拟主机
虚拟主机
域名注册
域名注册
711网络首页
站长工具
站长工具
网站源码
网站源码
站长论坛
站长论坛

 711网络 网页编程音乐小偷

asp.net小偷程序 类完整代码

来源: 互联网    日期:2008-7-25
 

using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Net;
using System.IO;
using System.Text;
//本代码作者为:http://www.aspx1.com (Asp.net学习门户)
//您可以任意使用,非法用途除外.
//转载请保留本声明
namespace Aspx1.Common
{
    /// <summary>
    /// thief
    /// </summary>
    public partial class Thief
    {
        public Thief()
        {
            //
            // TODO: 在此处添加构造函数逻辑
            //
        }
        public static string Post(string Web, string postData)
        {
            //在发送的内容里包括中文和空格
            string str = "";
            //地址
            postData = postData.Replace(" ", "%20");//替换空格
            try
            {
                //获取URL并进行发送字串
                HttpWebRequest myHttpWebRequest = (HttpWebRequest)WebRequest.Create(Web);
                Stream myStream = new MemoryStream();//定义这个Stream是只是为了得到发送字串 经过编码之后得到的byte的长度。
                StreamWriter myStreamWriter = new StreamWriter(myStream, Encoding.Default);//用默认编码 得到Stream           
   
                myStreamWriter.Write(postData);
                myStreamWriter.Flush();
                long len = myStream.Length;//目的完成
                myStreamWriter.Close();

                myHttpWebRequest.ContentType = "application/x-www-form-urlencoded";
                myHttpWebRequest.ContentLength = len;
                //如果字符串中存在中文 使用postData.Length得到长度和编码之
                //后的长度是不一样的:(
                myHttpWebRequest.Method = "POST";
                Stream newStream = myHttpWebRequest.GetRequestStream();
                //编码使用Encoding.Default 换来换去编码方法 还是用它得到的中文不会出现乱码,特别是把request("")得到的值写入sql
数据库的时候 真是奇怪^O^
                myStreamWriter = new StreamWriter(newStream, Encoding.Default);
                myStreamWriter.Write(postData);
                myStreamWriter.Close();
                //获取本次的回馈,先创建接收回馈的类HTTPWEBRESPONSE
                HttpWebResponse myHttpWebResponse = (HttpWebResponse)myHttpWebRequest.GetResponse();
                //创建接收回馈的字节流类
                Stream receiveStream = myHttpWebResponse.GetResponseStream();//得到回写的字节流 做爬虫的基础???
                Encoding encode;
                //encode = System.Text.Encoding.GetEncoding(myHttpWebResponse.CharacterSet.ToLower);
                switch (myHttpWebResponse.CharacterSet.ToLower())
                {
                    case "utf-8":
                        encode = System.Text.Encoding.GetEncoding("utf-8");
                        break;
                    case "gb2312":
                        encode = System.Text.Encoding.GetEncoding("gb2312");
                        break;
                    default:
                        encode = System.Text.Encoding.GetEncoding("gb2312"); //System.Text.Encoding.Default;
                        break;
                }
                // encode = System.Text.Encoding.Default;
                StreamReader readStream = new StreamReader(receiveStream, encode);//);

                str = readStream.ReadToEnd();
                readStream.Close();
                myHttpWebResponse.Close();
                return str;
            }
            catch (Exception e)
            {
                throw e;
            }
        }
        public static string Get(string url)
        {
            string tempurl = UrlEncode(url, System.Text.Encoding.GetEncoding("gb2312"));
            HttpWebRequest webr = (HttpWebRequest)WebRequest.Create(tempurl);
            HttpWebResponse wb = (HttpWebResponse)webr.GetResponse();
            Stream sr = wb.GetResponseStream();
            Encoding encode;
            //encode = System.Text.Encoding.GetEncoding(myHttpWebResponse.CharacterSet.ToLower);
            switch (wb.CharacterSet.ToLower())
            {
                case "utf-8":
                    encode = System.Text.Encoding.GetEncoding("utf-8");
                    break;
                case "gb2312":
                    encode = System.Text.Encoding.GetEncoding("gb2312");
                    break;
                default:
                    encode = System.Text.Encoding.GetEncoding("gb2312"); //System.Text.Encoding.Default;
                    break;
            }
            StreamReader sr1 = new StreamReader(sr, encode);
            string zz = sr1.ReadToEnd();
            sr1.Close();
            wb.Close();
            return zz;
        }
        public static Stream GetStreamRSS(string url)
        {
            string tempurl = UrlEncode(url, System.Text.Encoding.GetEncoding("gb2312"));
            HttpWebRequest webr = (HttpWebRequest)WebRequest.Create(tempurl);
            HttpWebResponse wb = (HttpWebResponse)webr.GetResponse();
            Stream sr = wb.GetResponseStream();
            wb.Close();
            return sr;
        }
        public static byte[] GetStream(string url)
        {
            string tempurl = UrlEncode(url, System.Text.Encoding.GetEncoding("gb2312"));
            byte[] by = null;
            HttpWebRequest webr = (HttpWebRequest)WebRequest.Create(tempurl);
            HttpWebResponse wb = (HttpWebResponse)webr.GetResponse();
            Stream sr = wb.GetResponseStream();
            long lo = wb.ContentLength;
            by = new byte[lo];
            int z = 0;
            long i = 0;
            while ((z = sr.ReadByte()) != -1)
            {
                by[i++] = Convert.ToByte(z);
            }
            wb.Close();
            return by;
        }
        public static string Get(string url, Encoding enc)
        {
            string tempurl = UrlEncode(url, enc);
            HttpWebRequest webr = (HttpWebRequest)WebRequest.Create(tempurl);
            HttpWebResponse wb = (HttpWebResponse)webr.GetResponse();
            Stream sr = wb.GetResponseStream();
            StreamReader sr1 = new StreamReader(sr, enc);
            string zz = sr1.ReadToEnd();
            sr1.Close();
            wb.Close();
            return zz;
        }
        private static string UrlEncode(string url, Encoding enc)
        {
            byte[] bs = enc.GetBytes(url);
            StringBuilder sb = new StringBuilder();
            for (int i = 0; i < bs.Length; i++)
            {
                if (bs[i] < 128)
                    sb.Append((char)bs[i]);
                else
                {
                    sb.Append("%" + bs[i++].ToString("x").PadLeft(2, '0'));
                    sb.Append("%" + bs[i].ToString("x").PadLeft(2, '0'));
                }
            }
            return sb.ToString();
        }
    }
}

本文来自: ASP.NET学习门户(http://www.aspx1.com) 详细出处参考:http://i.aspx1.com/showtopic-1398.htm###



更多的asp.net小偷程序 类完整代码请到论坛查看: http://BBS.TC711.COM



【 双击滚屏 】 【 评论 】 【 收藏 】 【 打印 】 【 关闭 】 来源: 互联网    日期:2008-7-25   

发 表 评 论
查看评论

  您的大名:
  • 尊重网上道德,遵守中华人民共和国的各项有关法律法规
  • 承担一切因您的行为而直接或间接导致的民事或刑事法律责任
  • 本站管理人员有权保留或删除其管辖留言中的任意内容
  • 本站有权在网站内转载或引用您的评论
  • 参与本评论即表明您已经阅读并接受上述条款
认证编码: 刷新验证码
点评内容: 字数0
  精品推荐  
  本月推荐  
  友情赞助  

关于我们 | 联系我们 | 广告投放 | 留言反馈 | 免费程序 | 虚拟主机 | 网站建设 |  网站推广 |  google_sitemap baidu_sitemap RSS订阅
本站所有资源均来自互联网,如有侵犯您的版权或其他问题,请通知管理员,我们会在最短的时间回复您
Copyright © 2005-2015 Tc711.Com All Rights Reserved 版权所有·711网络   蜀ICP备05021915号
110网监备案 信息产业备案 不良信息举报