在开发者界面用可以看到不少ptqrlogin初叶的 name

smart qqC#付出总结:

金沙注册送58 1金沙注册送58 2/**//// <summary>  登录
金沙注册送58 3        /// </summary>
金沙注册送58 4        /// <param name=”url”></param>
金沙注册送58 5        /// <param name=”paramList”></param>
金沙注册送58 6        /// <returns></returns>
金沙注册送58 7        public static string Login(String url, String paramList)
金沙注册送58 8金沙注册送58 9        金沙注册送58 10{
金沙注册送58 11            HttpWebResponse res = null;
金沙注册送58 12            string strResult = “”;
金沙注册送58 13            try
金沙注册送58 14金沙注册送58 15            金沙注册送58 16{
金沙注册送58 17                HttpWebRequest req = (HttpWebRequest)WebRequest.Create(url);
金沙注册送58 18                req.Method = “POST”;
金沙注册送58 19                req.ContentType = “application/x-www-form-urlencoded”;
金沙注册送58 20                req.AllowAutoRedirect = false;
金沙注册送58 21                CookieContainer cookieCon = new CookieContainer();
金沙注册送58 22                req.CookieContainer = cookieCon;
金沙注册送58 23                StringBuilder UrlEncoded = new StringBuilder();
金沙注册送58 24金沙注册送58 25                Char[] reserved = 金沙注册送58 26{ ‘?’, ‘=’, ‘&’ };
金沙注册送58 27                byte[] SomeBytes = null;
金沙注册送58 28                if (paramList != null)
金沙注册送58 29金沙注册送58 30                金沙注册送58 31{
金沙注册送58 32                    int i = 0, j;
金沙注册送58 33                    while (i < paramList.Length)
金沙注册送58 34金沙注册送58 35                    金沙注册送58 36{
金沙注册送58 37                        j = paramList.IndexOfAny(reserved, i);
金沙注册送58 38                        if (j == -1)
金沙注册送58 39金沙注册送58 40                        金沙注册送58 41{
金沙注册送58 42                            UrlEncoded.Append(HttpUtility.UrlEncode(paramList.Substring(i, paramList.Length – i)));
金沙注册送58 43                            break;
金沙注册送58 44                        }
金沙注册送58 45                        UrlEncoded.Append(HttpUtility.UrlEncode(paramList.Substring(i, j – i)));
金沙注册送58 46                        UrlEncoded.Append(paramList.Substring(j, 1));
金沙注册送58 47                        i = j + 1;
金沙注册送58 48                    }
金沙注册送58 49                    SomeBytes = Encoding.UTF8.GetBytes(UrlEncoded.ToString());
金沙注册送58 50                    req.ContentLength = SomeBytes.Length;
金沙注册送58 51                    Stream newStream = req.GetRequestStream();
金沙注册送58 52                    newStream.Write(SomeBytes, 0, SomeBytes.Length);
金沙注册送58 53                    newStream.Close();
金沙注册送58 54                }
金沙注册送58 55                else
金沙注册送58 56金沙注册送58 57                金沙注册送58 58{
金沙注册送58 59                    req.ContentLength = 0;
金沙注册送58 60                }
金沙注册送58 61
金沙注册送58 62                res = (HttpWebResponse)req.GetResponse();
金沙注册送58 63                cookieheader = req.CookieContainer.GetCookieHeader(new Uri(url));
金沙注册送58 64                Stream ReceiveStream = res.GetResponseStream();
金沙注册送58 65                Encoding encode = System.Text.Encoding.GetEncoding(“GBK”);
金沙注册送58 66                StreamReader sr = new StreamReader(ReceiveStream, encode);
金沙注册送58 67                Char[] read = new Char[256];
金沙注册送58 68检查二维码的失灵状态,模拟登录计算。                int count = sr.Read(read, 0, 256);
金沙注册送58 69                while (count > 0)
金沙注册送58 70金沙注册送58 71                金沙注册送58 72{
金沙注册送58 73                    String str = new String(read, 0, count);
金沙注册送58 74                    strResult += str;
金沙注册送58 75                    count = sr.Read(read, 0, 256);
金沙注册送58 76                }
金沙注册送58 77            }
金沙注册送58 78            catch (Exception e)
金沙注册送58 79金沙注册送58 80            金沙注册送58 81{
金沙注册送58 82                strResult = e.ToString();
金沙注册送58 83            }
金沙注册送58 84            finally
金沙注册送58 85金沙注册送58 86            金沙注册送58 87{
金沙注册送58 88                if (res != null)
金沙注册送58 89金沙注册送58 90                金沙注册送58 91{
金沙注册送58 92                    res.Close();
金沙注册送58 93                }
金沙注册送58 94            }
金沙注册送58 95            return strResult;
金沙注册送58 96        }
金沙注册送58 97金沙注册送58 98        /**//// <summary>  获取页面HTML
金沙注册送58 99        /// </summary>
金沙注册送58 100        /// <param name=”url”></param>
金沙注册送58 101        /// <param name=”paramList”></param>
金沙注册送58 102        /// <returns></returns>
金沙注册送58 103        public static string getPage(String url, String paramList)
金沙注册送58 104金沙注册送58 105        金沙注册送58 106{
金沙注册送58 107            HttpWebRequest req = (HttpWebRequest)WebRequest.Create(url);
金沙注册送58 108            req.Headers[“If-None-Match”] = “36d0ed736e88c71:d9f”;
金沙注册送58 109            req.Referer = “”;
金沙注册送58 110            CookieContainer cookieCon = new CookieContainer();
金沙注册送58 111            req.CookieContainer = cookieCon;
金沙注册送58 112            req.CookieContainer.SetCookies(new Uri(url), cookieheader);
金沙注册送58 113            HttpWebResponse res = (HttpWebResponse)req.GetResponse();
金沙注册送58 114            StreamReader sr = new StreamReader(res.GetResponseStream(),Encoding.Default);
金沙注册送58 115            string strResult = sr.ReadToEnd();
金沙注册送58 116            sr.Close();
金沙注册送58 117            return strResult;
金沙注册送58 118        }

金沙注册送58 119

漫天开发下来其实某个都不是很难,从壹开首贰维码
获取到最后的收发音信,基本上都以人云亦云浏览器的操作。都以依照http通信。一下就是此次新手学习http协议的最重要的1个类

调用:

金沙注册送58 120/// <summary>  登录
金沙注册送58 121        /// </summary>
金沙注册送58 122        /// <param name=”url”></param>
金沙注册送58 123        /// <param name=”paramList”></param>
金沙注册送58 124        /// <returns></returns>
金沙注册送58 125        public static string Login(String url, String paramList)
金沙注册送58 126        {
金沙注册送58 127            HttpWebResponse res = null;
金沙注册送58 128            string strResult = “”;
金沙注册送58 129            try
金沙注册送58 130            {
金沙注册送58 131                HttpWebRequest req = (HttpWebRequest)WebRequest.Create(url);
金沙注册送58 132                req.Method = “POST”;
金沙注册送58 133                req.ContentType = “application/x-www-form-urlencoded”;
金沙注册送58 134                req.AllowAutoRedirect = false;
金沙注册送58 135                CookieContainer cookieCon = new CookieContainer();
金沙注册送58 136                req.CookieContainer = cookieCon;
金沙注册送58 137                StringBuilder UrlEncoded = new StringBuilder();
金沙注册送58 138                Char[] reserved = { ‘?’, ‘=’, ‘&’ };
金沙注册送58 139                byte[] SomeBytes = null;
金沙注册送58 140                if (paramList != null)
金沙注册送58 141                {
金沙注册送58 142                    int i = 0, j;
金沙注册送58 143                    while (i < paramList.Length)
金沙注册送58 144                    {
金沙注册送58 145                        j = paramList.IndexOfAny(reserved, i);
金沙注册送58 146                        if (j == -1)
金沙注册送58 147                        {
金沙注册送58 148                            UrlEncoded.Append(HttpUtility.UrlEncode(paramList.Substring(i, paramList.Length – i)));
金沙注册送58 149                            break;
金沙注册送58 150                        }
金沙注册送58 151                        UrlEncoded.Append(HttpUtility.UrlEncode(paramList.Substring(i, j – i)));
金沙注册送58 152                        UrlEncoded.Append(paramList.Substring(j, 1));
金沙注册送58 153                        i = j + 1;
金沙注册送58 154                    }
金沙注册送58 155                    SomeBytes = Encoding.UTF8.GetBytes(UrlEncoded.ToString());
金沙注册送58 156                    req.ContentLength = SomeBytes.Length;
金沙注册送58 157                    Stream newStream = req.GetRequestStream();
金沙注册送58 158                    newStream.Write(SomeBytes, 0, SomeBytes.Length);
金沙注册送58 159                    newStream.Close();
金沙注册送58 160                }
金沙注册送58 161                else
金沙注册送58 162                {
金沙注册送58 163                    req.ContentLength = 0;
金沙注册送58 164                }
金沙注册送58 165
金沙注册送58 166                res = (HttpWebResponse)req.GetResponse();
金沙注册送58 167                cookieheader = req.CookieContainer.GetCookieHeader(new Uri(url));
金沙注册送58 168                Stream ReceiveStream = res.GetResponseStream();
金沙注册送58 169                Encoding encode = System.Text.Encoding.GetEncoding(“GBK”);
金沙注册送58 170                StreamReader sr = new StreamReader(ReceiveStream, encode);
金沙注册送58 171                Char[] read = new Char[256];
金沙注册送58 172                int count = sr.Read(read, 0, 256);
金沙注册送58 173                while (count > 0)
金沙注册送58 174                {
金沙注册送58 175                    String str = new String(read, 0, count);
金沙注册送58 176                    strResult += str;
金沙注册送58 177                    count = sr.Read(read, 0, 256);
金沙注册送58 178                }
金沙注册送58 179            }
金沙注册送58 180            catch (Exception e)
金沙注册送58 181            {
金沙注册送58 182                strResult = e.ToString();
金沙注册送58 183            }
金沙注册送58 184            finally
金沙注册送58 185            {
金沙注册送58 186                if (res != null)
金沙注册送58 187                {
金沙注册送58 188                    res.Close();
金沙注册送58 189                }
金沙注册送58 190            }
金沙注册送58 191            return strResult;
金沙注册送58 192        }
金沙注册送58 193        /// <summary>  获取页面HTML
金沙注册送58 194        /// </summary>
金沙注册送58 195        /// <param name=”url”></param>
金沙注册送58 196        /// <param name=”paramList”></param>
金沙注册送58 197        /// <returns></returns>
金沙注册送58 198        public static string getPage(String url, String paramList)
金沙注册送58 199        {
金沙注册送58 200            HttpWebRequest req = (HttpWebRequest)WebRequest.Create(url);
金沙注册送58 201            req.Headers[“If-None-Match”] = “36d0ed736e88c71:d9f”;
金沙注册送58 202            req.Referer = “”;
金沙注册送58 203            CookieContainer cookieCon = new CookieContainer();
金沙注册送58 204            req.CookieContainer = cookieCon;
金沙注册送58 205            req.CookieContainer.SetCookies(new Uri(url), cookieheader);
金沙注册送58 206            HttpWebResponse res = (HttpWebResponse)req.GetResponse();
金沙注册送58 207            StreamReader sr = new StreamReader(res.GetResponseStream(),Encoding.Default);
金沙注册送58 208            string strResult = sr.ReadToEnd();
金沙注册送58 209            sr.Close();
金沙注册送58 210            return strResult;
金沙注册送58 211        }

自个儿要做的正是 
模拟浏览器的操作,把它转换来大家团结的客户端。所以假使是浏览器里有个别大家都要效仿。接下来判断二维码失效,两秒三遍啊,弄1个Timer

/// <summary>
/// HTTP网络通讯类
/// </summary>
public static class HTTP
{

        string postData =
“userName=admin&password=pass&area=2006&Submit=%B5%C7+%C2%BC”;            
        string strLogin, strResult;
        strLogin = Login(“”, postData);

调用:

 

public static CookieContainer cookies = new CookieContainer();
static CookieCollection CookieCollection = new CookieCollection();
static CookieContainer CookieContainer = new CookieContainer();
/// <summary>
/// HTTP请求
/// </summary>
/// <param name=”url”>连接</param>
/// <param name=”enc”>编码</param>
/// <returns></returns>
public static string HttpGet(string url, Encoding enc)
{
HttpWebRequest request = (HttpWebRequest)WebRequest.Create;
request.Timeout = 10000;//设置10秒超时
request.Proxy = null;
request.Method = “GET”;
request.ContentType = “application/x-www-from-urlencoded”;
WebResponse response = request.GetResponse();
StreamReader reader = new StreamReader(response.GetResponseStream;
StringBuilder sb = new StringBuilder();
sb.Append(reader.ReadToEnd;
reader.Close();
reader.Dispose();
response.Close();
return sb.ToString();
}
/// <summary>
/// 带referer的http请求连接
/// </summary>
/// <param name=”url”></param>
/// <param name=”referer”></param>
/// <param name=”timeout”></param>
/// <param name=”encode”></param>
/// <param name=”NoProxy”></param>
/// <returns></returns>
public static string Get(string url, string referer =
“”, int
timeout = 100000, Encoding encode = null, bool NoProxy = false)
{
string dat;
HttpWebResponse res = null;
HttpWebRequest req;
try
{
req = (HttpWebRequest)WebRequest.Create;
req.CookieContainer = cookies;
req.AllowAutoRedirect = false;
req.Timeout = timeout;
req.Referer = referer;
if
req.Proxy = null;
req.UserAgent = “Mozilla/5.0 (Windows NT 10.0;%20WOW64; rv:47.0)
Gecko/20100101 Firefox/47.0”;
res = (HttpWebResponse)req.GetResponse();

         strResult = getPage(“”, “”);
//输出
         this.webBrowser1.Document.Write(strResult);

        string postData =
“userName=admin&password=pass&area=2006&Submit=%B5%C7+%C2%BC”;            
        string strLogin, strResult;
        strLogin = Login(“”, postData);

 

cookies.Add(res.Cookies);
}
catch (HttpException)
{
return “”;
}
catch (WebException)
{
return “”;
}
StreamReader reader;

         strResult = getPage(“”, “”);
//输出
         this.webBrowser1.Document.Write(strResult);

smart 类

reader = new StreamReader(res.GetResponseStream(), encode == null ?
Encoding.UTF8 : encode);
dat = reader.ReadToEnd();

#region 第二讲检查二维码状态
private static System.Timers.Timer StatuTimer = new
System.Timers.Timer();
public static void Login()
{
StatuTimer.AutoReset = true;
StatuTimer.Elapsed +=StatuTimer_Elapsed;
StatuTimer.Interval = 2000;
StatuTimer.Start();
}

res.Close();
req.Abort();

public static string Login_err = “其他”;
/// <summary>
/// 检查2维码状态
/// </summary>
public static void Login_GetStatu()
{
string dat;
dat =
HTTP.Get(string.Format(“”,
ptqrtoken));
string[] temp = dat.Split(‘\”);
switch (temp[1])
{
case (“六5”): //贰维码失效
Login_err = “贰维码失效”;
break;
case (“6陆”): //等待扫描
Login_err = “等待扫描”;
break;
case (“6柒”): //等待确认
Login_err = “等待确认”;
break;
case (“0”): //已经确认
Login_err = “已经承认”;
StatuTimer.Stop();
break;

return dat;
}
/// <summary>
/// 带referer data的http post
/// </summary>
/// <param name=”url”></param>
/// <param name=”data”></param>
/// <param name=”Referer”></param>
/// <param name=”timeout”></param>
/// <param name=”encode”></param>
/// <returns></returns>
public static string Post(string url, string data, string Referer =

method= “POST”, int timeout = 100000, Encoding encode = null)
{
string dat = “”;
HttpWebRequest req;
try
{
req = WebRequest.Create as HttpWebRequest;
req.CookieContainer = cookies;
req.ContentType = “application/x-www-form-urlencoded”;
req.Method = method;
req.Proxy = null;
req.Timeout = timeout;
req.UserAgent = “Mozilla/5.0 (Windows NT 10.0;%20WOW64; rv:47.0)
Gecko/20100101 Firefox/47.0”;
req.ProtocolVersion = HttpVersion.Version10;
req.Referer = Referer;

default: break;
}

byte[] mybyte = Encoding.Default.GetBytes;
req.ContentLength = mybyte.Length;

}

Stream stream = req.GetRequestStream();
stream.Write(mybyte, 0, mybyte.Length);

/// <summary>
/// 每两秒检查二次2维码状态
/// </summary>
private static void StatuTimer_Elapsed(object sender,
System.Timers.ElapsedEventArgs e)
{
Login_GetStatu();
}
#endregion

HttpWebResponse res = req.GetResponse() as HttpWebResponse;

 

cookies.Add(res.Cookies);
stream.Close();

 

StreamReader SR = new StreamReader(res.GetResponseStream(), encode ==
null ? Encoding.UTF8 : encode);
dat = SR.ReadToEnd();
res.Close();
req.Abort();
}
catch (HttpException)
{
return “”;
}
catch (WebException)
{
return “”;
}

HTTP 类

return dat;
}
/// <summary>
/// Hash 转换
/// </summary>
/// <param name=”s”></param>
/// <returns></returns>
public static int Hash33
{
var e = 0;
foreach (var t in s)
e += (e << 5) + t;
return int.MaxValue & e;
}
/// <summary>
/// 获取CookieCollection下 所有cookie
/// </summary>
/// <param name=”cc”></param>
/// <returns></returns>
public static string GetAllCookies(CookieCollection cc)
{
//List<Cookie> lstCookies = new List<Cookie>();
string lstCookies = “”;
ArrayList table = (ArrayList)cc.GetType().InvokeMember(“m_list”,
System.Reflection.BindingFlags.NonPublic |
System.Reflection.BindingFlags.GetField |
System.Reflection.BindingFlags.Instance, null, cc, new object[] { });

 

if (table != null)
{
for (int i = 0; i < table.Count; i++)
{
string[] tacookie = table[i].ToString().Split;
lstCookies = tacookie[1].ToString;
}
}

/// <summary>
/// 带referer的http请求连接
/// </summary>
/// <param name=”url”></param>
/// <param name=”referer”></param>
/// <param name=”timeout”></param>
/// <param name=”encode”></param>
/// <param name=”NoProxy”></param>
/// <returns></returns>
public static string Get(string url, string referer =
“”, int
timeout = 100000, Encoding encode = null, bool NoProxy = false)
{
string dat;
金沙注册送58 ,HttpWebResponse res = null;
HttpWebRequest req;
try
{
req = (HttpWebRequest)WebRequest.Create(url);
req.CookieContainer = cookies;
req.AllowAutoRedirect = false;
req.Timeout = timeout;
req.Referer = referer;
if (NoProxy)
req.Proxy = null;
req.UserAgent = “Mozilla/5.0 (Windows NT 10.0;%20WOW64; rv:47.0)
Gecko/20100101 Firefox/47.0”;
res = (HttpWebResponse)req.GetResponse();

return lstCookies;
}
public delegate void Post_Async_Action(string data);
private class Post_Async_Data
{
public HttpWebRequest req;
public Post_Async_Action post_Async_Action;
}
public static void Post_Async(string url, string PostData,
Post_Async_Action action, string Referer =
“”, int
timeout = 100000)
{
HttpWebRequest req = WebRequest.Create as HttpWebRequest;
req.CookieContainer = cookies;
req.ContentType = “application/x-www-form-urlencoded”;
req.Method = “POST”;
req.Referer = Referer;
req.UserAgent = “Mozilla/5.0 (Windows NT 10.0;%20WOW64; rv:47.0)
Gecko/20100101 Firefox/47.0”;
req.Proxy = null;
req.ProtocolVersion = HttpVersion.Version10;
req.ContinueTimeout = timeout;

cookies.Add(res.Cookies);
}
catch (HttpException)
{
return “”;
}
catch (WebException)
{
return “”;
}
StreamReader reader;

ASCIIEncoding encoding = new ASCIIEncoding();
byte[] data = encoding.GetBytes;
Stream stream = req.GetRequestStream();
stream.Write(data, 0, data.Length);
stream.Close();

reader = new StreamReader(res.GetResponseStream(), encode == null ?
Encoding.UTF8 : encode);
dat = reader.ReadToEnd();

Post_Async_Data dat = new Post_Async_Data();
dat.req = req;
dat.post_Async_Action = action;
req.BeginGetResponse(new AsyncCallback(Post_Async_ResponesProceed),
dat);
}

res.Close();
req.Abort();

private static void Post_Async_ResponesProceed(IAsyncResult ar)
{
StreamReader reader = null;
Post_Async_Data dat = ar.AsyncState as Post_Async_Data;
HttpWebRequest req = dat.req;
HttpWebResponse res = req.GetResponse() as HttpWebResponse;
reader = new StreamReader(res.GetResponseStream;
string temp = reader.ReadToEnd();
res.Close();
req.Abort();
dat.post_Async_Action;
}
}

return dat;
}

于是计算下来差不七只借使知道一点http协议,基本上网页版的顺序,我们都能够随便的转换来图形桌面版,从而根据自个儿本身业务开始展览开发。

 

协理本人接触过
最多的便是天猫客,TmallTaobao京东店数据,当然这个都以法定api的。kaola jd
tianmao 等购物网站的归类,商品数量爬取分析。

首先次发新手教程很多大概看的不是很明亮,可是有源码。能够依照源码的声明举行学习。个中最重大的是json的解析了。因为本人也是新手,所以重重都以要查一下资料才明白的。希望这几讲能给1部分就学http协议的新手一些启迪(小编也是新手,说错勿怪。)

接下去正是做个图形界面的smart qq机器人。

相关文章

网站地图xml地图