簡體   English   中英

Form.Post 中的 NameValueCollection 顯示 FIELDS 和 VALUES

[英]NameValueCollection from Form.Post show FIELDS and VALUES

我需要從 POST 中獲取所有 FIELD 和 VALUES。

我有以下內容,它只返回字段但不返回值。

NameValueCollection authForm = Request.Form;
String[] a = authForm.AllKeys;

for (i = 0; i < a.Length; i++)
{
    frm += ("Form: " + a[i] + " : " + "<br>");
}

Response.Write(frm);

我可以添加什么 frm 字符串來顯示值?

更新:

我使用了初始代碼

    NameValueCollection authForm = Request.Form;
    foreach (string key in authForm.AllKeys)
    {
        frm += ("Key: " + key + ", Value: " + authForm[key] + "<br/>");
    }

效果很好。 我將嘗試下面的新變體。

NameValueCollection authForm = Request.Form;
StringBuilder sb = new StringBuilder();
foreach (string key in authForm.AllKeys)
{
    sb.AppendFormat(
        "Key: {0}, Value: {1}<br/>", 
        HttpUtility.HtmlEncode(key), 
        HttpUtility.HtmlEncode(authForm[key])
    );
}
Response.Write(sb.ToString());

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM