高分求高手解决模拟登录问题!!!C#牛人
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 m百度
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(url);
string url = "http://wappass.baidu.com/passport/";
string postData = "login_username="+textBox1.Text+"&login_loginpass="+textBox2.Text+"&aaa=%E7%99%BB%E5%BD%95&login=yes&can_input=0&u=&login_start_time=1359431843&tpl=&tn=&pu=&ssid=&from=&bd_page_type=&uid=1359431843588_646&login_username_input=0&type=";
byte[] byteRequest = Encoding.Default.GetBytes(postData);
HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(url);
request.CookieContainer = cookieContainer;
request.Referer = url;
request.ContentType = "application/x-www-form-urlencoded";
request.ContentLength = byteRequest.Length; //附加信息长度
request.Accept = "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8";
request.UserAgent = "Mozilla/5.0 (Windows NT 6.1; rv:18.0) Gecko/20100101 Firefox/18.0";
request.Method = "POST";
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
Stream stream = response.GetResponseStream(); //转换为数据流
StreamReader reader = new StreamReader(stream);
string html = reader.ReadToEnd(); //通过StreamReader类读取流
html = richTextBox1.Text;
reader.Close();
stream.Close();
}
public CookieContainer cookieContainer { get; set; }
}
}
求解决,代码有两处出错,不知道为什么,寻找路过的高手帮忙解决
小弟我不甚感激!!!!! c# login 模拟登录 --------------------编程问答--------------------
--------------------编程问答-------------------- --------------------编程问答-------------------- 这手……好新啊…… --------------------编程问答-------------------- 这里有指定:
string url = "http://wappass.baidu.com/passport/";
HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(url);
string postData = "login_username=" + textBox1.Text + "&login_loginpass=" + textBox2.Text + "&aaa=%E7%99%BB%E5%BD%95&login=yes&can_input=0&u=&login_start_time=1359431843&tpl=&tn=&pu=&ssid=&from=&bd_page_type=&uid=1359431843588_646&login_username_input=0&type=";
byte[] byteRequest = Encoding.Default.GetBytes(postData);
request = (HttpWebRequest)HttpWebRequest.Create(url);
request.CookieContainer = cookieContainer;
request.Referer = url;
request.ContentType = "application/x-www-form-urlencoded";
request.ContentLength = byteRequest.Length; //附加信息长度
request.Accept = "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8";
request.UserAgent = "Mozilla/5.0 (Windows NT 6.1; rv:18.0) Gecko/20100101 Firefox/18.0";
request.Method = "POST";
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
Stream stream = response.GetResponseStream(); //转换为数据流
StreamReader reader = new StreamReader(stream);
string html = reader.ReadToEnd(); //通过StreamReader类读取流
html = richTextBox1.Text;
reader.Close();
stream.Close();
request.ContentLength = byteRequest.Length; //附加信息长度
但是你没有Stream.Writer
Steam.Write(byteRequest, 0, byteRequest.Length);
请自行调试将该代码加入到正确位置. --------------------编程问答--------------------
string url = "http://wappass.baidu.com/passport/";--------------------编程问答-------------------- 哥,你是干嘛的? --------------------编程问答-------------------- 1.url 和 Request 定义出现混乱。
HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(url);
string postData = "login_username=" + textBox1.Text + "&login_loginpass=" + textBox2.Text + "&aaa=%E7%99%BB%E5%BD%95&login=yes&can_input=0&u=&login_start_time=1359431843&tpl=&tn=&pu=&ssid=&from=&bd_page_type=&uid=1359431843588_646&login_username_input=0&type=";
byte[] byteRequest = Encoding.Default.GetBytes(postData);
request = (HttpWebRequest)HttpWebRequest.Create(url);
request.CookieContainer = cookieContainer;
request.Referer = url;
request.ContentType = "application/x-www-form-urlencoded";
request.ContentLength = byteRequest.Length; //附加信息长度
request.Accept = "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8";
request.UserAgent = "Mozilla/5.0 (Windows NT 6.1; rv:18.0) Gecko/20100101 Firefox/18.0";
request.Method = "POST";
Stream newStream = request.GetRequestStream();
// Send the data.
newStream.Write(byteRequest, 0, byteRequest.Length);
newStream.Close();
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
StreamReader reader = new StreamReader(response.GetResponseStream(), Encoding.Default);
string html = reader.ReadToEnd(); //通过StreamReader类读取流
html = richTextBox1.Text;
reader.Close();
stream.Close();
2.没有写入POST 的数据。 --------------------编程问答--------------------
没办法网上找不到相关的视频教程找到一些文章教程,试试写代码! --------------------编程问答-------------------- 飘过吧。。。。。该从基础学学吧。给的建议。 --------------------编程问答--------------------
大哥你能教教我吗? --------------------编程问答-------------------- 你定义url的位置不对吧。。。。要放在上面啊,
而且你定义了2次request了。。。 --------------------编程问答-------------------- 個人建議
HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(url); 這語句出現了兩次
把第一次的刪掉就可以了
补充:.NET技术 , C#