我知道如何在asp.net中添加Basic的Header Authorization:
webreq.Headers.Add("Authorization", "BASIC " + Convert.ToBase64String(authBytes) );
与OAuth的标头授权相似吗?
webreq.Headers.Add("Authorization", "OAuth oauth_consumer_key=\"...something..........\", oauth_nonce=\"......something............\", oauth_signature=\"......something............\", oauth_signature_method=\"......something............\", oauth_timestamp=\"......something............\", oauth_token=\"......something............\", oauth_version=\"......something............\"");
或我该怎么办?
答案 0 :(得分:0)
在 OAuth 2 中,您将使用持票人令牌,因此添加标头的代码将如下所示
webreq.Headers.Add("Authorization", "Bearer -----Your token here-------");
答案 1 :(得分:0)
我解决:
string headerFormat = "OAuth oauth_nonce=\"{0}\", oauth_signature_method=\"{1}\", " +
"oauth_timestamp=\"{2}\", oauth_consumer_key=\"{3}\", oauth_signature=\"{4}\", oauth_version=\"{5}\"";
string authHeader = string.Format(headerFormat,
Uri.EscapeDataString(oauth_nonce),
Uri.EscapeDataString(oauth_signature_method),
Uri.EscapeDataString(oauth_timestamp),
Uri.EscapeDataString(oauth_consumer_key),
Uri.EscapeDataString(oauth_signature),
Uri.EscapeDataString(oauth_version)
);
WebRequest request = WebRequest.Create(url);
request.ContentType = "application/json; charset=utf-8";
request.Headers.Add("Authorization", authHeader);
请记住生成oauth_nonce,oauth_signatur和oauth_timestamp。