Help logging in to Jira online over c#

Nuno Silva June 21, 2020

Hi,

 

Need some help to understand and how to fix this when trying to connect to jira over c#. 

url format is:

 

String baseURL = "https://mycompanyname.jira.com/rest/";
String loginAPI = "auth/1/session";

 

Whenever I try to execute this, I get a 401. I've tried using my email with api key, username without email format with api key, and both with password and all get a 401... Totally clueless.

 

public void loginToJira()
{

try {

WebRequest request = WebRequest.Create(this.baseURL + this.loginAPI);
String postData = "{\"username\":\"" + this.loginUsername + "\",\"password\":\"" + this.loginPassword + "\"}";
byte[] byteArray = Encoding.UTF8.GetBytes(postData);
request.Method = "POST";
request.ContentType = "application/json";
request.ContentLength = byteArray.Length;

Stream dataStream = request.GetRequestStream();
dataStream.Write(byteArray, 0, byteArray.Length);
dataStream.Close();

WebResponse response = request.GetResponse();
dataStream = response.GetResponseStream();
StreamReader reader = new StreamReader(dataStream);
String responseFromServer = reader.ReadToEnd();
this.loginResponse = responseFromServer;
reader.Close();
dataStream.Close();
response.Close();

}
catch (Exception ex)
{
string texto = ex.Message;
}
}

0 answers

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events