在后台服务器上下载一个Form验证的页面,如何把用户明和密码提交过去?

huangcaibing 2008-05-26 09:59:27
public void Send(string sPostUrl, string strFile)
{
HttpWebRequest request = (HttpWebRequest) WebRequest.Create(sPostUrl);
request.CookieContainer=sSessionId;
request.Method="get";

//request.Timeout=2240;
HttpWebResponse response = (HttpWebResponse) request.GetResponse();

byte[] buf = new byte[1024];
int count=0;
if(System.IO.File.Exists(strFile))
{
System.IO.File.Delete(strFile);
}
System.IO.FileStream fs=new System.IO.FileStream(strFile,System.IO.FileMode.CreateNew,System.IO.FileAccess.Write);
while(true)
{
//resStream.Write(byte1,0,byte1.Length);
buf = new byte[1024];
count = response.GetResponseStream().Read(buf, 0, buf.Length);
if (count<=0)
{
break;
}
fs.Write(buf,0,count);
}

fs.Close();
}

下载一个页面存到服务器上,现在的问题这个页面需要Form验证,怎么先提交用户名和密码先进行验证?
...全文
84 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
Plougher 2008-05-26
  • 打赏
  • 举报
回复
学习关注下
一品梅 2008-05-26
  • 打赏
  • 举报
回复
private void OnPostInfoClick(object sender, System.EventArgs e) 
{
string strId = UserId_TextBox.Text;
string strName = Name_TextBox.Text;

ASCIIEncoding encoding=new ASCIIEncoding();
string postData="userid="+strId;
postData += ("&username="+strName);
byte[] data = encoding.GetBytes(postData);

// Prepare web request...
HttpWebRequest myRequest =
(HttpWebRequest)WebRequest.Create("http://localhost/MyIdentity/Default.aspx");
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();
}

周公 2008-05-26
  • 打赏
  • 举报
回复
using System;
using System.Net;
using System.Text;
using System.IO;


public class Test
{
// Specify the URL to receive the request.
public static void Main (string[] args)
{
HttpWebRequest request = (HttpWebRequest)WebRequest.Create (url);

// Set some reasonable limits on resources used by this request
request.MaximumAutomaticRedirections = 4;
request.MaximumResponseHeadersLength = 4;
// Set credentials to use for this request.
request.Credentials = new NetworkCredential(struserName,
strpassword);//struserName,strpassword对应着用户名和帐号
HttpWebResponse response = (HttpWebResponse)request.GetResponse ();

Console.WriteLine ("Content length is {0}", response.ContentLength);
Console.WriteLine ("Content type is {0}", response.ContentType);

// Get the stream associated with the response.
Stream receiveStream = response.GetResponseStream ();

// Pipes the stream to a higher level stream reader with the required encoding format.
StreamReader readStream = new StreamReader (receiveStream, Encoding.UTF8);

Console.WriteLine ("Response stream received.");
Console.WriteLine (readStream.ReadToEnd ());
response.Close ();
readStream.Close ();
}
}

/*
The output from this example will vary depending on the value passed into Main
but will be similar to the following:

Content length is 1542
Content type is text/html; charset=utf-8
Response stream received.
<html>
...
</html>

*/
周公 2008-05-26
  • 打赏
  • 举报
回复
比如用户名是:username
用户密码是:password
表单上的用户名控件是txtUsername,用户密码控件是:txtPassword
登录页面是:login.aspx
你这么试试:
HttpWebRequest request = (HttpWebRequest) WebRequest.Create("login.aspx?txtUsername=username&&txtPassword=password);
huangcaibing 2008-05-26
  • 打赏
  • 举报
回复
自己UP

62,046

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧