Advertisement
Guest User

Untitled

a guest
Mar 4th, 2016
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.96 KB | None | 0 0
  1. var httpWebRequest = (HttpWebRequest)WebRequest.Create("http://url");
  2.  
  3. String username = "abc";
  4. String password = "123";
  5. String encoded = Convert.ToBase64String(System.Text.Encoding.GetEncoding("ISO-8859-1").GetBytes(username + ":" + password));
  6. httpWebRequest.Headers.Add("Authorization", "Basic " + encoded);
  7. httpWebRequest.ContentType = "application/json";
  8. httpWebRequest.Method = "POST";
  9.  
  10. public static void AddAuthorizationHeader(ref HttpWebRequest request)
  11. {
  12. string username = //load value from web.config
  13. string password = //load value from web.config
  14. string encoded = Convert.ToBase64String(System.Text.Encoding.GetEncoding("ISO-8859-1").GetBytes(username + ":" + password));
  15. request.Headers.Add("Authorization", "Basic " + encoded);
  16. }
  17.  
  18. HttpWebRequest request = new HttpWebRequest();
  19. UtilityClass.AddAuthorizationHeader(ref request);
  20. request.ContentType = "application/json";
  21. request.Method = "POST";
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement