title: C# implement oauth 1.0 by using HMAC-SHA1 (without token)
body: <p>I have tried to implement the Oauth 1.0 by using HMAC-SHA1 (without token details).  While debug it, It's always return the following exception  "The remote server returned an error: (401) Unauthorized". But the same credential works fine in Postman. </p>
  
  <p>I have the Token secret </p>
  
  <pre><code>var key = EscapeUriDataStringRfc3986(consumerSecret) + "&amp;";" 
  </code></pre>
  
  <p>as well while form the key details.</p>
  
  <pre><code>try
  {
      var httpWebRequest = (HttpWebRequest)WebRequest.Create(url);
      httpWebRequest.Method = "GET";
  
      var timeStamp = ((int)(DateTime.UtcNow - new DateTime(1970, 1, 1)).TotalSeconds).ToString();
      var nonce = Convert.ToBase64String(Encoding.UTF8.GetBytes(timeStamp));
  
      var signatureBaseString = Escape(httpWebRequest.Method.ToUpper()) + "&amp;";
      signatureBaseString += EscapeUriDataStringRfc3986(url.ToLower()) + "&amp;";
      signatureBaseString += EscapeUriDataStringRfc3986(
          "oauth_consumer_key=" + EscapeUriDataStringRfc3986(consumerKey) + "&amp;" +
          "oauth_nonce=" + EscapeUriDataStringRfc3986(nonce) + "&amp;" +
          "oauth_signature_method=" + EscapeUriDataStringRfc3986("HMAC-SHA1") + "&amp;" +
          "oauth_timestamp=" + EscapeUriDataStringRfc3986(timeStamp) + "&amp;" +
          "oauth_version=" + EscapeUriDataStringRfc3986("1.0"));
      //MessageBox.Show(@"signatureBaseString: " + signatureBaseString);
  
      var key = EscapeUriDataStringRfc3986(consumerSecret) + "&amp;";
      MessageBox.Show(@"key: " + key);
      var signatureEncoding = new ASCIIEncoding();
      var keyBytes = signatureEncoding.GetBytes(key);
      var signatureBaseBytes = signatureEncoding.GetBytes(signatureBaseString);
      string signatureString;
      using (var hmacsha1 = new HMACSHA1(keyBytes))
      {
          var hashBytes = hmacsha1.ComputeHash(signatureBaseBytes);
          signatureString = Convert.ToBase64String(hashBytes);
      }
      signatureString = EscapeUriDataStringRfc3986(signatureString);
      MessageBox.Show(@"signatureString: " + signatureString);
  
      var header =
              "oauth_consumer_key=" + SimpleQuote(consumerKey) + "," +
              "oauth_nonce=" + SimpleQuote(nonce) + "," +
              "oauth_signature_method=" + SimpleQuote("HMAC-SHA1") + "," +
              "oauth_timestamp=" + SimpleQuote(timeStamp) + "," +
              "oauth_version=" + SimpleQuote("1.0") + "," +
              "oauth_signature= " + SimpleQuote(signatureString);
  
      MessageBox.Show(@"header: " + header);
      httpWebRequest.Headers.Add(HttpRequestHeader.Authorization, header);
  
      var response = httpWebRequest.GetResponse();
      var characterSet = ((HttpWebResponse)response).CharacterSet;
      var responseEncoding = characterSet == ""
          ? Encoding.UTF8
          : Encoding.GetEncoding(characterSet ?? "utf-8");
      var responsestream = response.GetResponseStream();
      if (responsestream == null)
      {
          //throw new ArgumentNullException(nameof(characterSet));
      }
      using (responsestream)
      {
          var reader = new StreamReader(responsestream, responseEncoding);
          var result = reader.ReadToEnd();
          Console.WriteLine(@"result: " + result);
      }
  }
  catch (Exception ex)
  {
      MessageBox.Show("Error:"+ex.Message.ToString());
  }
  </code></pre>