When i try to login with rest api using c# . i am not get any response after request is submitted
below is c# sample code i am using to get all projects which i got from the community suggestions. please suggest
public class JiraManager
{
private const string m_BaseUrl = "http://companyname.atlassian.net/rest/api/2/";
private string m_Username;
private string m_Password;
public JiraManager(string username, string password)
{
m_Username = username;
m_Password = password;
}
private string GetEncodedCredentials()
{
string mergedCredentials = string.Format("{0}:{1}", m_Username, m_Password);
byte[] byteCredentials = UTF8Encoding.UTF8.GetBytes(mergedCredentials);
return Convert.ToBase64String(byteCredentials);
}
public List<ProjectDescription> GetProjects()
{
List<ProjectDescription> projects = new List<ProjectDescription>();
string projectsString = RunQuery1(JiraResource.project);
return JsonConvert.DeserializeObject<List<ProjectDescription>>(projectsString);
}
protected string RunQuery1(
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;
}