Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var url = new Uri("http://localhost:8090/rest/auth/latest/session?os_username=tempusername&os_password=temppwd");
- var request = WebRequest.Create(url) as HttpWebRequest;
- if (null == request)
- {
- return "";
- }
- request.Method = "POST";
- request.ContentType = "application/json";
- request.ContentLength = 200;
- request.KeepAlive = false;
- using (var response = request.GetResponse() as HttpWebResponse)
- {
- }
- public enum JiraResource
- {
- project
- }
- protected string RunQuery(
- JiraResource resource,
- string argument = null,
- string data = null,
- string method = "GET")
- {
- string url = string.Format("{0}{1}/", m_BaseUrl, resource.ToString());
- if (argument != null)
- {
- url = string.Format("{0}{1}/", url, argument);
- }
- HttpWebRequest request = WebRequest.Create(url) as HttpWebRequest;
- request.ContentType = "application/json";
- request.Method = method;
- if (data != null)
- {
- using (StreamWriter writer = new StreamWriter(request.GetRequestStream()))
- {
- writer.Write(data);
- }
- }
- string base64Credentials = GetEncodedCredentials();
- request.Headers.Add("Authorization", "Basic " + base64Credentials);
- HttpWebResponse response = request.GetResponse() as HttpWebResponse;
- string result = string.Empty;
- using (StreamReader reader = new StreamReader(response.GetResponseStream()))
- {
- result = reader.ReadToEnd();
- }
- return result;
- }
- private string GetEncodedCredentials()
- {
- string mergedCredentials = string.Format("{0}:{1}", m_Username, m_Password);
- byte[] byteCredentials = UTF8Encoding.UTF8.GetBytes(mergedCredentials);
- return Convert.ToBase64String(byteCredentials);
- }
- var mergedCredentials = string.Format("{0}:{1}", username, password);
- var byteCredentials = Encoding.UTF8.GetBytes(mergedCredentials);
- var encodedCredentials = Convert.ToBase64String(byteCredentials);
- using (WebClient webClient = new WebClient())
- {
- webClient.Headers.Set("Authorization", "Basic " + encodedCredentials);
- return webClient.DownloadString(url);
- }
- public async Task<JiraCookie> GetCookieAsync(string myJsonPass, string JiraCookieEndpointUrl)
- {
- using (var client = new HttpClient())
- {
- var response = await client.PostAsync(
- JiraCookieEndpointUrl,
- new StringContent(myJsonPass, Encoding.UTF8, "application/json"));
- var json = response.Content.ReadAsStringAsync().Result;
- var jiraCookie= JsonConvert.DeserializeObject<JiraCookie>(json);
- return jArr;
- }
- }
- public class JiraCookie
- {
- public Session session { get; set; }
- }
- public class Session
- {
- public string name { get; set; }
- public string value { get; set; }
- }
- {
- "session" : -{
- "name" : JSESSIONID,
- "value" : cookieValue
- }
Add Comment
Please, Sign In to add comment