} /*newUrl="http://bizweb.sdeport.com"+response.GetResponseHeader("Location"); int start = newUrl.IndexOf("("); int end =newUrl.IndexOf(")"); //得到每次传递网址的一个编号 Sid=newUrl.Substring(start,end-start+1);*/
using System.Runtime.InteropServices; using System.IO; using System.Text; using System.Reflection; using System.Diagnostics; using System.Net; 这是需要引用的名称空间
using System; using System.Runtime.InteropServices; using System.IO; using System.Text; using System.Reflection; using System.Diagnostics; using System.Net; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Windows.Forms; using mshtml; namespace RegSystemSolution { public partial class Form1 : Form { public mshtml.HTMLDocumentClass Tdoc; public Reg.clsReg Info = new Reg.clsReg(); public string acount, pwd, mz, email, sex, Uyear, Umonth, Uday, Usheng, Ucity; public Form1() { InitializeComponent(); } private void ShowUrl() { string url = "http://xy.mop.com/regist/L.do?a=2efe4070dcb14fb2&s=6"; Browser.Navigate(url);
还有,你准备使用webbrowser吗?还是通过底层Http请求
什么CSDNReader
你可以参考一下
Microsoft.mshtml.dll,microsoft Html object libary.dll
之后你就可以通过如下方法来实现:
这是我实现的部分代码,你可以参考一下:
private void Form1_Load(object sender, System.EventArgs e)
{
if (exitflag==true)
{
Application.Exit();
}
else
{
this.txt_pwd.Text=m_strupwd;
this.axWebBrowser1.Navigate(this.m_strCardUserLogin,ref nullObject,ref nullObject, ref nullObject,ref nullObject);
this.label3.Text="正在连接请稍侯…………";
this.button4.Enabled=false;
} /*newUrl="http://bizweb.sdeport.com"+response.GetResponseHeader("Location");
int start = newUrl.IndexOf("(");
int end =newUrl.IndexOf(")");
//得到每次传递网址的一个编号
Sid=newUrl.Substring(start,end-start+1);*/
}private void axWebBrowser1_DocumentComplete(object sender, AxSHDocVw.DWebBrowserEvents2_DocumentCompleteEvent e)
{
this.LoginPage();
}/// <summary>
/// 登陆内容填写/执行登陆事件
/// </summary>
/// <returns></returns>
public void LoginPage()
{
try
{
mshtml.HTMLDocumentClass doc = (mshtml.HTMLDocumentClass)axWebBrowser1.Document;
mshtml.HTMLInputElementClass textPassword = (mshtml.HTMLInputElementClass)doc.getElementById("textPassword");
textPassword.value=this.m_strupwd;
mshtml.HTMLInputElementClass btnLogin = (mshtml.HTMLInputElementClass)doc.getElementById("btnLogin");
btnLogin.click();
//flag=true; }
catch(Exception ex)
{
//flag=false;
MsgBox("错误代码:407"+"\r\n"+ex.Message);
exitflag=true;
}
if (exitflag==true)
{
shutdown();
}
}
HTTP请求无非两种,post和get,你说的这种是post请求。
比如一个页面上有个文本框,name="aaa",那么你需要拼接一个post数据字符串为"aaa=value1",如果有多个,那么就是"aaa=value1&bbb=value2&ccc=value3",依此类推。其中需要注意的是,中文和特殊字符要做编码处理。
然后,通过HttpWebRequest和HttpWebResponse发送接受请求,发送的目标url就是form标签中的action值。
当然,上面说的是最最最最简单的一个例子,现实情况中,还需要考虑到cookie、验证码等其它诸多问题。
不过,学习归学习,不用用这做坏事情。
楼主不是做程序的吧? 语气不像
-----------------这个用程序完全可以做到
不用手工参与进来!!!如果你想输入字符串然后手动点提交
你可以用webbrowser实现如果你想程序自动输入字符串并且自动提交
可以用WebClient或者webrequest和webresponse实现
具体的去Google
现成代码很多
System.Net.HttpWebResponse response;
request = (HttpWebRequest)WebRequest.Create(url);
request.ContentType = "text/html";
request.Accept = "*/*"; //接受任意文件
byte[] byte1 = Encoding.Default.GetBytes(postdata);
request.ContentType = "application/x-www-form-urlencoded";
request.KeepAlive = false;
request.Method = "post";//post上传方式
request.ContentLength = byte1.Length;
response = (HttpWebResponse)request.GetResponse();
提示无法转换呀
using System.IO;
using System.Text;
using System.Reflection;
using System.Diagnostics;
using System.Net;
这是需要引用的名称空间
我将你说的空间都引用进来了呀
function aaa()
{
window.open("你要登陆的页面.aspx","_parent","");
}<asp:button id="submit" runat="server" onclientclick="aaa()">页面间传值可以用session["abc"]="你要传的值";
接收页面: string bb=session["abc"].tostring().trim();
不知道我理解的对不对
using System.Runtime.InteropServices;
using System.IO;
using System.Text;
using System.Reflection;
using System.Diagnostics;
using System.Net;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Windows.Forms;
using mshtml;
namespace RegSystemSolution
{
public partial class Form1 : Form
{
public mshtml.HTMLDocumentClass Tdoc;
public Reg.clsReg Info = new Reg.clsReg();
public string acount, pwd, mz, email, sex, Uyear, Umonth, Uday, Usheng, Ucity;
public Form1()
{
InitializeComponent();
}
private void ShowUrl()
{
string url = "http://xy.mop.com/regist/L.do?a=2efe4070dcb14fb2&s=6";
Browser.Navigate(url);
}
private void Form1_Load(object sender, EventArgs e)
{
ShowUrl(); } private void Browser_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
{
//timer1.Enabled = true;
mshtml.HTMLDocumentClass doc = (mshtml.HTMLDocumentClass)Browser.Document;
mshtml.HTMLInputElementClass textPassword = (mshtml.HTMLInputElementClass)doc.getElementById("password");
textPassword.value = "2q3434234";
}
private void ShowInfo()
{
try
{
string Tname = Browser.Document.ActiveElement.Name.ToString();
switch (Tname)
{
case "nickname":
Browser.Document.ActiveElement.InnerText = Info.GetYHM().ToString();
break;
case "password":
case "passwd2":
Browser.Document.ActiveElement.InnerText = Info.get_User_Pwd().ToString();
break;
case "realname":
Browser.Document.ActiveElement.InnerText = Info.get_User_XM().ToString();
break;
case "email":
Browser.Document.ActiveElement.InnerText = Info.GetEmail().ToString();
break;
case "birthdayYear":
//Browser.Document.ActiveElement.InnerText = Info.get_User_Year().ToString();
break;
}
}
catch (Exception)
{ }
} private void Browser_LocationChanged(object sender, EventArgs e)
{
MessageBox.Show(Browser.Document.Title.ToString());
} private void toolStrip1_ItemClicked(object sender, ToolStripItemClickedEventArgs e)
{
} private void toolStrip1_Click(object sender, EventArgs e)
{
ShowUrl();
} private void Browser_PreviewKeyDown(object sender, PreviewKeyDownEventArgs e)
{
ShowInfo();
} }
}