2015-01-09 70 views
0

我知道如何添加基本的頭球授權在asp.net:HTTP POST請求:添加頁眉授權的OAuth

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

[爲oauth令牌請求傳遞授權標頭]可能的重複(http://stackoverflow.com/questions/8984463/passing-authorization-header-for-oauth-token-request) –

回答

0

的OAuth 2你可以使用一個承載令牌,以便代碼添加頁眉會像下面

webreq.Headers.Add("Authorization", "Bearer -----Your token here-------"); 
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。