无法从C#中的Request.Params中读取值 [英] unable to read values from Request.Params in c#
问题描述
我有以下一段代码使我无法从Request.Params
中读取值.现在,我只想读取从发件人传递来的值(在收件人中),即用户名和SAMLResponse.
I have following piece of code which is troubling me to read the value from Request.Params
. Right now I just want to read values (in receiver) that I'm passing from sender i.e. username and SAMLResponse.
发件人
protected void Button1_Click(object sender, EventArgs e)
{
HttpWebRequest httpWReq = (HttpWebRequest)WebRequest.Create("MY URL");
httpWReq.Method = "Post";
XElement obj = XElement.Load(@"Load.xml");
StringBuilder postData = new StringBuilder();
postData = postData.Append("username=user&SAMLResponse=").Append(obj.ToString());
byte[] data = Encoding.UTF8.GetBytes(postData.ToString());
httpWReq.Method = "POST";
httpWReq.ContentType = "text/xml;encoding='utf-8'";
httpWReq.ContentLength = data.Length;
using (Stream stream = httpWReq.GetRequestStream())
{
stream.Write(data, 0, data.Length);
}
HttpWebResponse response = (HttpWebResponse)httpWReq.GetResponse();
string responseString = new StreamReader(response.GetResponseStream()).ReadToEnd();
}
接收器
public ActionResult LoginSSO()
{
string rawSamlData, WindowName;
SSOModel objSSOModel = new SSOModel();
string str = Request.Params["username"];
str = Request.Params["SAMLResponse"];
...
..
}
错误:
任何想法,怎么了?
推荐答案
这在我的应用程序中有效.
This works in my application.
-
正如其他答复者所说,在发件人中将内容类型更改为
"application/x-www-form-urlencoded"
.
As other answerers said, changed content-type to
"application/x-www-form-urlencoded"
in Sender.
在接收器中将string str = Request.Params["username"];
更改为string str = Request.Form["username"];
或string str = Request["username"];
.
我希望它们也可以在您的应用程序中使用.
I hope they will work in your application as well.
这篇关于无法从C#中的Request.Params中读取值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!