簡體   English   中英

通過localhost上的IIS從ASP.NET/C#連接到Atlassian JIRA

[英]Connecting to Atlassian JIRA from ASP.NET/C# via IIS on localhost

我正在嘗試創建一個小型實用程序,其中需要登錄JIRA(Atlassian.com)。

我們的JIRA服務器托管在Atlassian-example.atlassian.net上,而我要開發的應用程序托管在IIS上的本地服務器(192.168.1.XXX)上。 該應用程序使用ASP.NET/C#。

我嘗試運行示例JIRA示例,該示例提供了一個簡單的登錄頁面,用戶應在其中輸入其JIRA憑據。 到目前為止,一切都很好。

如果有人輸入了錯誤的用戶名/密碼,應用程序將顯示一些錯誤消息(我認為該消息已損壞):

The remote server returned an error: (401) Unauthorized.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 

Exception Details: System.Net.WebException: The remote server returned an error: (401) Unauthorized.

Source Error: 

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

Stack Trace: 


[WebException: The remote server returned an error: (401) Unauthorized.]
   System.Net.HttpWebRequest.GetResponse() +1743
   JiraExample.JiraManager.RunQuery(JiraResource resource, String argument, String data, String method) +597
   JiraExample.JiraManager.GetProjects() +100
   JiraExample.Login.Button1_Click(Object sender, EventArgs e) +143
   System.Web.UI.WebControls.Button.OnClick(EventArgs e) +11802193
   System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +150
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1735

但是,如果輸入正確的用戶名/密碼,則會顯示“無法訪問此站點”,並指出防火牆/代理問題。

是因為缺少FQDN還是因為專用IP地址? 如果是,是否可以將JIRA響應轉發到我的應用程序?

謝謝

編輯:

此示例使用基本身份驗證:

    HttpWebRequest request = WebRequest.Create(url) as HttpWebRequest;
    request.ContentType = "application/json";
    request.Method = method;
    string base64Credentials = GetEncodedCredentials();
    request.Headers.Add("Authorization", "Basic " + base64Credentials);

    private string GetEncodedCredentials()
    {
       string mergedCredentials = string.Format("{0}:{1}", m_Username, m_Password);
       byte[] byteCredentials = UTF8Encoding.UTF8.GetBytes(mergedCredentials);
      return Convert.ToBase64String(byteCredentials);
   }

(以上代碼清單為部分內容)

這是因為專用IP地址。 您使用的示例是圍繞OAuth構建的,該過程涉及令牌的往返。 請參閱這篇Jira OAuth文章。 為簡單起見,請通過對您的username:password進行base64編碼來使用基本身份驗證 ,並將其(帶有“ Basic”前綴)添加到Authorization標頭中。

var encodedAuth = System.Convert.ToBase64String(
    System.Text.Encoding.UTF8.GetBytes("username:password")
);
var Client = new HttpClient();
Client.DefaultRequestHeaders.Add("Authorization", "Basic " + encodedAuth);

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM