http://www.sufeinet.com/plugin.php?id=keke_group

苏飞论坛

 找回密码
 马上注册

QQ登录

只需一步,快速开始

分布式系统框架(V2.0) 轻松承载百亿数据,千万流量!讨论专区 - 源码下载 - 官方教程

HttpHelper爬虫框架(V2.7-含.netcore) HttpHelper官方出品,爬虫框架讨论区 - 源码下载 - 在线测试和代码生成

HttpHelper爬虫类(V2.0) 开源的爬虫类,支持多种模式和属性 源码 - 代码生成器 - 讨论区 - 教程- 例子

查看: 3950|回复: 6

[其他] post登录

[复制链接]
发表于 2013-2-28 22:30:00 | 显示全部楼层 |阅读模式
[code=csharp]using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Net;
using System.IO;

namespace login
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            HttpWebRequest request;
            HttpWebResponse respone;
            CookieContainer cc = new CookieContainer();
            string content = GetHtml("http://www.sufeinet.com/member.php?mod=logging&action=login");
            string formhash = Content(content, "\"formhash\" value=\"", "\" />");//取formhash
            string postdata = "formhash=" + formhash + "&referer=http%3A%2F%2Fbbs.fishc.com%2F&loginfield=username&username=" + txtuser.Text + "&password=" + txtpass.Text + "&questionid=0&answer=&cookietime=2592000";
            textBox1.Text = content;
            textBox2.Text = formhash;
            byte[] postdatastr = Encoding.UTF8.GetBytes(postdata);

            try
            {
                request = (HttpWebRequest)WebRequest.Create("http://bbs.fishc.com/member.php?mod=logging&action=login");
                request.CookieContainer = cc;
                request.Method = "post";
                request.ContentType = "application/x-www-form-urlencoded";
                request.ContentLength = postdatastr.Length;
                Stream stream = request.GetRequestStream();
                //发送数据
                stream.Write(postdatastr, 0, postdatastr.Length);
                stream.Close();

                respone = (HttpWebResponse)request.GetResponse();


            }
            catch
            {

            }


        }
        //得到网页源码
        public string GetHtml(string url)
        {
            HttpWebRequest requrest = (HttpWebRequest)HttpWebRequest.Create(url);
            HttpWebResponse respone = (HttpWebResponse)requrest.GetResponse();
            Stream getrespone = respone.GetResponseStream();
            StreamReader sr = new StreamReader(getrespone, Encoding.Default);
            string html = sr.ReadToEnd();
            sr.Close();
            getrespone.Close();
            return html;



        }
        //取中间字符
        public string Content(string s, string s1, string s2)
        {
            int n1, n2;
            n1 = s.IndexOf(s1, 0) + s1.Length;
            n2 = s.IndexOf(s2, n1);
            return s.Substring(n1, n2 - n1);

        }
    }

}[/code]

论坛登录不了,是我少了东西还是?


1. 开通SVIP会员,免费下载本站所有源码,不限次数据,不限时间
2. 加官方QQ群,加官方微信群获取更多资源和帮助
3. 找站长苏飞做网站、商城、CRM、小程序、App、爬虫相关、项目外包等点这里
发表于 2013-3-1 00:43:55 | 显示全部楼层
睡醒后给你录个视频,告诉你发送请求和响应是怎么回事,有时间看看http协议
 楼主| 发表于 2013-3-1 00:45:38 | 显示全部楼层
软件家园 发表于 2013-3-1 00:43
睡醒后给你录个视频,告诉你发送请求和响应是怎么回事,有时间看看http协议

好的,谢谢您了,非常感谢你写的源码,以后直接用了!!!
发表于 2013-3-1 09:56:25 | 显示全部楼层
闷油瓶 发表于 2013-3-1 00:45
好的,谢谢您了,非常感谢你写的源码,以后直接用了!!!

你看过我的Http绝技吗?你写的代码基本不对,呵呵
 楼主| 发表于 2013-3-1 11:07:31 | 显示全部楼层
admin 发表于 2013-3-1 09:56
你看过我的Http绝技吗?你写的代码基本不对,呵呵

看着有点晕,不过现在好了,必须要求看了,要不然自己在瞎写.
发表于 2013-3-1 11:10:13 | 显示全部楼层
闷油瓶 发表于 2013-3-1 11:07
看着有点晕,不过现在好了,必须要求看了,要不然自己在瞎写.

你看看吧,我写的都是从基本的开始的,看懂了你自己就能修改了。祝你好运,呵呵
 楼主| 发表于 2013-3-1 12:00:09 | 显示全部楼层
admin 发表于 2013-3-1 11:10
你看看吧,我写的都是从基本的开始的,看懂了你自己就能修改了。祝你好运,呵呵

嗯,好的,非常感谢
您需要登录后才可以回帖 登录 | 马上注册

本版积分规则

QQ|手机版|小黑屋|手机版|联系我们|关于我们|广告合作|苏飞论坛 ( 豫ICP备18043678号-2)

GMT+8, 2024-4-18 12:30

© 2014-2021

快速回复 返回顶部 返回列表