gpt4 book ai didi

c# - 如何使用服务器端代码从 http post headers 获取表单数据

转载 作者:可可西里 更新时间:2023-11-01 16:39:56 25 4
gpt4 key购买 nike

我正在收到来自 MS 登录的 Azure Active Directory 回调。帖子在标题中包含一个 id token ,需要在服务器端将其读入一个字符串变量。

我可以在 network/headers/formdata 下的 chrome 开发工具中看到数据。我已经遍历了标题集合——它不存在。你到底是怎么访问这些数据的?

用于显示标题的代码(实际上使用的是 vb.net,但它现在只占市场的一小部分,所以我发布的是 c#,如果需要我可以很容易地翻译它。):

Dim loop1, loop2 As Integer
Dim arr1(), arr2() As String
Dim coll As NameValueCollection

' Load Header collection into NameValueCollection object.
coll = Request.Headers

' Put the names of all keys into a string array.
arr1 = coll.AllKeys
For loop1 = 0 To arr1.GetUpperBound(0)
txtOutput.Text += "Key: " & arr1(loop1) & vbCrLf
arr2 = coll.GetValues(loop1)
' Get all values under this key.
For loop2 = 0 To arr2.GetUpperBound(0)
txtOutput.Text += "Value " & CStr(loop2) & ": " & Server.HtmlEncode(arr2(loop2)) & vbCrLf & vbCrLf
Next loop2
Next loop1

我期待在 header 集合中找到此数据,但它不在那里。

最佳答案

你几乎成功了。答案在你的问题中。使用 coll = Request.Form 而不是 coll = Request.Headers

关于c# - 如何使用服务器端代码从 http post headers 获取表单数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56509232/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com