找回密码
 立即注册
查看: 1040|回复: 19

论坛登录 感觉没错但就是失败啊

[复制链接]

2034

回帖

2万

基友

2万

积分

仙人7层 Lv.16

Invincible

Rank: 10Rank: 10Rank: 10

发表于 2014-5-9 22:32:27 | 显示全部楼层 |阅读模式
  1.    internal class CHIUser
  2.     {
  3.         private string Username,Password;
  4.         private HttpWebRequest req;
  5.         private HttpWebResponse res;
  6.         private CookieContainer cookies;
  7.         internal void SetDefaultRequest(HttpWebRequest req,string Method="POST")
  8.         {
  9.             req.Accept = "*/*";
  10.             req.Headers.Set(HttpRequestHeader.AcceptLanguage, "zh-cn");
  11.             req.UserAgent = "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1)";
  12.             req.ContentType = "application/x-www-form-urlencoded";
  13.             req.Headers.Set("Cache-Control", "no-cache");
  14.             req.Method = Method;
  15.             req.Timeout = 8000;
  16.             req.KeepAlive = true;
  17.         }
  18.         internal CHIUser(string UN, string PW,out bool suc)
  19.         {
  20.             Username = UN;
  21.             Password = PW;
  22.             cookies = new CookieContainer();
  23.             try
  24.             {
  25.                 req = (HttpWebRequest)WebRequest.Create("http://www.258ch.com/");
  26.                 SetDefaultRequest(req,"GET");
  27.                 req.CookieContainer = cookies;
  28.                 req.GetResponse();
  29.                 req = (HttpWebRequest)
  30.                     WebRequest.Create("http://www.258ch.com/member.php?mod=logging&action=login&loginsubmit=yes&infloat=yes&lssubmit=yes&inajax=1");
  31.                 SetDefaultRequest(req);
  32.                 req.CookieContainer = cookies;
  33.                 string poststr=
  34.                    "username=" +
  35.                     GBKEncoding(UN) + "&password=" + PW +
  36.                     "&quickforward=yes&handlekey=ls";
  37.                 byte[] postdata = Encoding.Unicode.GetBytes(poststr);

  38.                 Stream st = req.GetRequestStream();
  39.                 st.Write(postdata, 0, postdata.Length);
  40.                 st.Close();
  41.                 res = (HttpWebResponse)req.GetResponse();
  42.                 StreamReader sr = new StreamReader(res.GetResponseStream());
  43.                 MessageBox.Show(sr.ReadToEnd());
  44.                 sr.Close();
  45.                 foreach (Cookie c in cookies.GetCookies(new Uri("http://www.258ch.com/")))
  46.                 {
  47.                         MessageBox.Show(c.Name +"="+ c.Value);
  48.                 }
  49.             }
  50.             catch (Exception ex)
  51.             {
  52.                 MessageBox.Show(ex.Message);
  53.                 suc = false;
  54.                 return;
  55.             }
  56.             suc = true;
  57.         }
  58.         internal string GBKEncoding(string text)
  59.         {
  60.             byte[] strByte = Encoding.Default.GetBytes(text);
  61.             StringBuilder sb = new StringBuilder();
  62.             foreach (var by in strByte)
  63.             {
  64.                 if ((by >= 48 && by <= 57) || (by >= 65 && by <= 90) || (by >= 97 && by <= 122))
  65.                 { sb.Append((char)by);}
  66.                 else{sb.Append('%'+by.ToString("X")); }
  67.             }
  68.             return sb.ToString();
  69.         }
  70.     }
  71. }
复制代码
While the truncheon may be used in lieu of conversation words will always retain their power.
回复

使用道具 举报

2034

回帖

2万

基友

2万

积分

仙人7层 Lv.16

Invincible

Rank: 10Rank: 10Rank: 10

 楼主| 发表于 2014-5-9 22:35:15 | 显示全部楼层
While the truncheon may be used in lieu of conversation words will always retain their power.
回复 支持 反对

使用道具 举报

2034

回帖

2万

基友

2万

积分

仙人7层 Lv.16

Invincible

Rank: 10Rank: 10Rank: 10

 楼主| 发表于 2014-5-9 22:35:23 | 显示全部楼层
While the truncheon may be used in lieu of conversation words will always retain their power.
回复 支持 反对

使用道具 举报

629

回帖

862

基友

3790

积分

通神5段 Lv.8

Rank: 4

发表于 2014-5-9 22:57:44 | 显示全部楼层
这是c吗。。。
回复

使用道具 举报

2034

回帖

2万

基友

2万

积分

仙人7层 Lv.16

Invincible

Rank: 10Rank: 10Rank: 10

 楼主| 发表于 2014-5-9 23:19:15 | 显示全部楼层

c#
While the truncheon may be used in lieu of conversation words will always retain their power.
回复 支持 反对

使用道具 举报

1249

回帖

2万

基友

2万

积分

萨菲尔斯

【直♂男】

Rank: 17Rank: 17Rank: 17Rank: 17Rank: 17

苍海的女仆伯爵荣耀

发表于 2014-5-9 23:22:09 | 显示全部楼层
没学过c#
Five贴吧个人网站www.fivekuai.com
回复

使用道具 举报

2034

回帖

2万

基友

2万

积分

仙人7层 Lv.16

Invincible

Rank: 10Rank: 10Rank: 10

 楼主| 发表于 2014-5-9 23:38:39 | 显示全部楼层
While the truncheon may be used in lieu of conversation words will always retain their power.
回复 支持 反对

使用道具 举报

2034

回帖

2万

基友

2万

积分

仙人7层 Lv.16

Invincible

Rank: 10Rank: 10Rank: 10

 楼主| 发表于 2014-5-9 23:40:06 | 显示全部楼层

应该能看懂 帮我看看
While the truncheon may be used in lieu of conversation words will always retain their power.
回复 支持 反对

使用道具 举报

7657

回帖

86万

基友

34万

积分

天下一番

Rank: 18Rank: 18Rank: 18Rank: 18Rank: 18

伯爵荣耀

发表于 2014-5-9 23:44:54 | 显示全部楼层
...返回啥
回复

使用道具 举报

2034

回帖

2万

基友

2万

积分

仙人7层 Lv.16

Invincible

Rank: 10Rank: 10Rank: 10

 楼主| 发表于 2014-5-9 23:49:32 | 显示全部楼层
本帖最后由 Rise 于 2014-5-9 23:50 编辑

---------------------------

---------------------------
<?xml version="1.0" encoding="gbk"?>

<root><![CDATA[&#65533;&#65533;&#504;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#1403;&#65533;&#65533;&#65533;&#65533;&#65533;&#503;&#65533;&#65533;&#1463;&#65533;<script type="text/javascript" reload="1">if(typeof errorhandle_=='function') {errorhandle_('&#65533;&#65533;&#504;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#1403;&#65533;&#65533;&#65533;&#65533;&#65533;&#503;&#65533;&#65533;&#1463;&#65533;', {});}</script>]]></root>
---------------------------
确定   
---------------------------

While the truncheon may be used in lieu of conversation words will always retain their power.
回复 支持 反对

使用道具 举报

1249

回帖

2万

基友

2万

积分

萨菲尔斯

【直♂男】

Rank: 17Rank: 17Rank: 17Rank: 17Rank: 17

苍海的女仆伯爵荣耀

发表于 2014-5-10 01:08:44 | 显示全部楼层
Rise 发表于 2014-5-9 23:49
---------------------------

---------------------------

编码没有问题吧
Five贴吧个人网站www.fivekuai.com
回复 支持 反对

使用道具 举报

2034

回帖

2万

基友

2万

积分

仙人7层 Lv.16

Invincible

Rank: 10Rank: 10Rank: 10

 楼主| 发表于 2014-5-10 10:42:04 | 显示全部楼层

不知
While the truncheon may be used in lieu of conversation words will always retain their power.
回复 支持 反对

使用道具 举报

2103

回帖

4万

基友

2万

积分

死神左手

Rank: 16Rank: 16Rank: 16Rank: 16

发表于 2014-5-10 11:20:09 | 显示全部楼层
不会C#
回复

使用道具 举报

7657

回帖

86万

基友

34万

积分

天下一番

Rank: 18Rank: 18Rank: 18Rank: 18Rank: 18

伯爵荣耀

发表于 2014-5-10 11:53:52 | 显示全部楼层
Rise 发表于 2014-5-9 23:49
---------------------------

---------------------------

先把编码调利索吧= =
回复 支持 反对

使用道具 举报

2034

回帖

2万

基友

2万

积分

仙人7层 Lv.16

Invincible

Rank: 10Rank: 10Rank: 10

 楼主| 发表于 2014-5-10 12:00:44 | 显示全部楼层
龙 发表于 2014-5-10 11:53
先把编码调利索吧= =

狗屎gbk不会用啊
While the truncheon may be used in lieu of conversation words will always retain their power.
回复 支持 反对

使用道具 举报

7657

回帖

86万

基友

34万

积分

天下一番

Rank: 18Rank: 18Rank: 18Rank: 18Rank: 18

伯爵荣耀

发表于 2014-5-10 13:43:22 | 显示全部楼层
Rise 发表于 2014-5-10 12:00
狗屎gbk不会用啊
  1. StreamReader sr = new StreamReader(res.GetResponseStream(), Encoding.Default);
复制代码

c#不像java  各种操作并不是强行按照平台的ansi来编码的  所以每次指定一个编码是个好习惯~
回复 支持 反对

使用道具 举报

2034

回帖

2万

基友

2万

积分

仙人7层 Lv.16

Invincible

Rank: 10Rank: 10Rank: 10

 楼主| 发表于 2014-5-10 18:29:36 | 显示全部楼层
龙 发表于 2014-5-10 13:43
c#不像java  各种操作并不是强行按照平台的ansi来编码的  所以每次指定一个编码是个好习惯~

貌似成功了
While the truncheon may be used in lieu of conversation words will always retain their power.
回复 支持 反对

使用道具 举报

555

回帖

1411

基友

3035

积分

通神5段 Lv.8

Rank: 4

发表于 2014-5-16 00:56:55 | 显示全部楼层
C语言?》
回复

使用道具 举报

2034

回帖

2万

基友

2万

积分

仙人7层 Lv.16

Invincible

Rank: 10Rank: 10Rank: 10

 楼主| 发表于 2014-5-16 20:14:55 | 显示全部楼层
While the truncheon may be used in lieu of conversation words will always retain their power.
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|苍海国际 ( 鲁ICP备13020644号-1 )

GMT+8, 2024-5-20 18:16 , Processed in 0.045100 second(s), 29 queries .

Powered by Discuz! Theme By eRic Modified by 4bpa

© CangHai International We Do Our Rights!

返回顶部