Guest User

Untitled

a guest
Mar 5th, 2018
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.77 KB | None | 0 0
  1. var url = new Uri("http://localhost:8090/rest/auth/latest/session?os_username=tempusername&os_password=temppwd");
  2. var request = WebRequest.Create(url) as HttpWebRequest;
  3. if (null == request)
  4. {
  5. return "";
  6. }
  7. request.Method = "POST";
  8. request.ContentType = "application/json";
  9. request.ContentLength = 200;
  10. request.KeepAlive = false;
  11. using (var response = request.GetResponse() as HttpWebResponse)
  12. {
  13. }
  14.  
  15. public enum JiraResource
  16. {
  17. project
  18. }
  19.  
  20. protected string RunQuery(
  21. JiraResource resource,
  22. string argument = null,
  23. string data = null,
  24. string method = "GET")
  25. {
  26. string url = string.Format("{0}{1}/", m_BaseUrl, resource.ToString());
  27.  
  28. if (argument != null)
  29. {
  30. url = string.Format("{0}{1}/", url, argument);
  31. }
  32.  
  33. HttpWebRequest request = WebRequest.Create(url) as HttpWebRequest;
  34. request.ContentType = "application/json";
  35. request.Method = method;
  36.  
  37. if (data != null)
  38. {
  39. using (StreamWriter writer = new StreamWriter(request.GetRequestStream()))
  40. {
  41. writer.Write(data);
  42. }
  43. }
  44.  
  45. string base64Credentials = GetEncodedCredentials();
  46. request.Headers.Add("Authorization", "Basic " + base64Credentials);
  47.  
  48. HttpWebResponse response = request.GetResponse() as HttpWebResponse;
  49.  
  50. string result = string.Empty;
  51. using (StreamReader reader = new StreamReader(response.GetResponseStream()))
  52. {
  53. result = reader.ReadToEnd();
  54. }
  55.  
  56. return result;
  57. }
  58.  
  59. private string GetEncodedCredentials()
  60. {
  61. string mergedCredentials = string.Format("{0}:{1}", m_Username, m_Password);
  62. byte[] byteCredentials = UTF8Encoding.UTF8.GetBytes(mergedCredentials);
  63. return Convert.ToBase64String(byteCredentials);
  64. }
  65.  
  66. var mergedCredentials = string.Format("{0}:{1}", username, password);
  67. var byteCredentials = Encoding.UTF8.GetBytes(mergedCredentials);
  68. var encodedCredentials = Convert.ToBase64String(byteCredentials);
  69.  
  70. using (WebClient webClient = new WebClient())
  71. {
  72. webClient.Headers.Set("Authorization", "Basic " + encodedCredentials);
  73.  
  74. return webClient.DownloadString(url);
  75. }
  76.  
  77. public async Task<JiraCookie> GetCookieAsync(string myJsonPass, string JiraCookieEndpointUrl)
  78. {
  79. using (var client = new HttpClient())
  80. {
  81. var response = await client.PostAsync(
  82. JiraCookieEndpointUrl,
  83. new StringContent(myJsonPass, Encoding.UTF8, "application/json"));
  84. var json = response.Content.ReadAsStringAsync().Result;
  85. var jiraCookie= JsonConvert.DeserializeObject<JiraCookie>(json);
  86. return jArr;
  87. }
  88. }
  89.  
  90. public class JiraCookie
  91. {
  92. public Session session { get; set; }
  93. }
  94.  
  95. public class Session
  96. {
  97. public string name { get; set; }
  98. public string value { get; set; }
  99. }
  100.  
  101. {
  102. "session" : -{
  103. "name" : JSESSIONID,
  104. "value" : cookieValue
  105. }
Add Comment
Please, Sign In to add comment