//当前网页Login.jsp
<html>
<head>
<title>Logon</title>
</head>
<body>
<form action="login.action">
<input type="text" name="user">
<input type="password" name="password">
<input type="submit" value="fegegfefefe">
</form>
</body>
</html><package name="default" extends="struts-default"> <action name="login" class="com.jamesby.struts2.Login">
<result name="success">/result.jsp</result>
</action> </package>上面是我要psot的网页,是通用struts2写的。我自己写的。下面是配置文件,不过输入什么
点击按钮的时候都会迁移到result.jsp 这个网页。但是通过c# 的HttpWebRequest 实现post,
得到的返回值总是当前的网页Login.jsp的内容。
下面是c#的代码                string strUrl = "http://127.0.0.1:8080/test1/Login.jsp";                //准备数据
                Encoding encoding = Encoding.GetEncoding("UTF-8");
                string postData = "?user=1&password=2&submit=fegegfefefe";
                byte[] data = encoding.GetBytes(postData);                //准备请求
                HttpWebRequest myRequest = (HttpWebRequest)WebRequest.Create(strUrl);
                myRequest.Method = "POST";
                myRequest.ContentType = "application/x-www-form-urlencoded";
                myRequest.ContentLength = data.Length;
                Stream newStream = myRequest.GetRequestStream();                //发送数据
                newStream.Write(data, 0, data.Length);
                newStream.Close();
                WebResponse response = myRequest.GetResponse();
                Uri x = response.ResponseUri;
                Stream resStream = response.GetResponseStream();
                StreamReader sr = new StreamReader(resStream, System.Text.Encoding.Default);
                string s = sr.ReadToEnd();
                resStream.Close();
                sr.Close();                Console.WriteLine(s);