关于自动登陆网站代码改写后不能正常登录求助
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Text;
using System.Net;
using System.IO;
public partial class CJ_Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
string username = "hbgjh ";
string password = "hbgjh ";
ASCIIEncoding encoding = new ASCIIEncoding();
string postData = "userName= " + username;
postData += ( "&PassWord= " + password);
byte[] data = encoding.GetBytes(postData);
// Prepare web request...
HttpWebRequest myRequest =
(HttpWebRequest)WebRequest.Create( "http://www.locknet.com.cn/member/checklogin.asp ");
myRequest.Method = "POST ";
myRequest.ContentType = "application/x-www-form-urlencoded ";
myRequest.ContentLength = data.Length;
Stream newStream = myRequest.GetRequestStream();
// Send the data....
newStream.Write(data, 0, data.Length);
newStream.Close();
// Get response
HttpWebResponse myResponse = (HttpWebResponse)myRequest.GetResponse();
StreamReader reader = new StreamReader(myResponse.GetResponseStream(), Encoding.Default);
string content = reader.ReadToEnd();
Response.Write(content);
}
}
以上源码是网上“C#实现通过HttpWebRequest发送POST请求实现网站自动登陆
”文章根据我自己实际要求改写.
string username = "hbgjh ";