读书人

asp.net 模拟post的时候跳转过去的有关

发布时间: 2013-11-13 14:04:18 作者: rapoo

asp.net 模拟post的时候跳转过去的问题.
模拟post的时候能否自动跳转到post页面?.注意是在.CS 模拟post的情况
[解决办法]

/// <summary>
/// Post数据
/// </summary>
private static bool HttpPost(string sUrl, string data, ref string sError)
{
string postData = data;
try
{
if (string.IsNullOrEmpty("sUrl")) throw new Exception("URL地址有误");
//将数据提交到代理
WebRequest myWebRequest = WebRequest.Create(sUrl);
myWebRequest.Method = "POST";
myWebRequest.Timeout = 4000;
myWebRequest.ContentType = "application/x-www-form-urlencoded";
Stream streamReq = myWebRequest.GetRequestStream();
byte[] byteArray = Encoding.GetEncoding("GB2312").GetBytes(postData);
streamReq.Write(byteArray, 0, byteArray.Length);
streamReq.Close();

//获取系统返回的数据
WebResponse myWebResponse = myWebRequest.GetResponse();
StreamReader sr = new StreamReader(myWebResponse.GetResponseStream());
string res = sr.ReadToEnd();
sr.Close();



}
catch (Exception e)
{

}
}


试试这个函数吧,自己调试一下
[解决办法]
HttpWebRequest myRequest =
(HttpWebRequest)WebRequest.Create("http:www.here.com/login.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(response.GetResponseStream(),Encoding.Default);
string content = reader.ReadToEnd();
Console.WriteLine(content);

[解决办法]
参考
[解决办法]
呵呵,今天我也研究了半天这个问题,解决了
[解决办法]
我用的
<body>

<form name="form1" id="form1" action="<%=url%>" method="post">
<input name="username" type="hidden" value="<%=username%>" />
<input name="pass" type="hidden" value="<%=pass %>" />



</form>
<script type="text/javascript">

form1.submit();

</script>
</body>

前台用js提交form,form里的内容,后台由.cs产生。

读书人网 >asp.net

热点推荐