【问题标题】:Get signed OAuth request in the Authorization header of a HTTP Request c#在 HTTP 请求 c# 的授权标头中获取签名的 OAuth 请求
【发布时间】:2017-12-25 12:18:43
【问题描述】:

我正在使用下面的代码从 url 获取授权标头,但授权字段始终返回为 null

 string url = "https://xyz.appdirect.com/api/integration/v1/events/abc-123";
            HttpWebRequest httpWebRequest = (HttpWebRequest)WebRequest.Create(url);
            string value = httpWebRequest.Headers["Authorization"];

另外,当我遵循 MSDN 代码时,我得到的标题为空值

  WebRequest request = WebRequest.Create(url);
            request.Method = WebRequestMethods.Http.Get;
            NameValueCollection authHeader = request.Headers;

            if (authHeader.Count > 0)
            {
                foreach (string strKey in authHeader)
                {
                    string s = strKey + " = " + request.Headers[strKey] + "<br />\n";
                    Console.WriteLine(String.Format(" Key Value header: {0}", authHeader[strKey]));

                }
            }
            else
            {
                Console.WriteLine(String.Format("No headers found"));

            }

获取授权标头的正确方法是什么?

【问题讨论】:

    标签: c# oauth httpwebrequest oauth-1.0a


    【解决方案1】:

    简单的解决方案是从HttpContext 获取标头,但我将其复杂化了做其他事情,而不是直接从HttpContext 读取它。

    NameValueCollection authHeader = HttpContext.Current.Request.Headers;
    foreach (string strKey in authHeader)
    {
        _logger.Info(String.Format(" Key Value header: {0}", authHeader[strKey]));
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-05-04
      • 1970-01-01
      • 2015-01-27
      • 1970-01-01
      • 2017-08-07
      相关资源
      最近更新 更多