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.
Sender
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();
}
Receiver
public ActionResult LoginSSO()
{
string rawSamlData, WindowName;
SSOModel objSSOModel = new SSOModel();
string str = Request.Params["username"];
str = Request.Params["SAMLResponse"];
...
..
}
Error:
Any idea, what is going wrong?
I see a few issues with your code.
obj.ToString()
as it may contain characters that will confuse things.application/x-www-form-urlencoded
This works in my application.
As other answerers said, changed content-type to
"application/x-www-form-urlencoded"
in Sender.Changed
string str = Request.Params["username"];
tostring str = Request.Form["username"];
orstring str = Request["username"];
in Receiver.I hope they will work in your application as well.
Can you change this line:
to this:
And give us a result?
https://msdn.microsoft.com/en-us/library/debx8sh9(v=vs.110).aspx