无法从C#中的Request.Params中读取值 [英] unable to read values from Request.Params in c#

查看:350
本文介绍了无法从C#中的Request.Params中读取值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下一段代码使我无法从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.

  1. 正如其他答复者所说,在发件人中将内容类型更改为"application/x-www-form-urlencoded".

  1. 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆