我正在尝试创建一个小型实用程序应用程序,我需要登录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);
}
(上面的代码清单是部分的)
答案 0 :(得分:0)
这是因为私有IP地址。您正在使用的示例是围绕OAuth构建的,其中涉及到往返的令牌。请参阅此Jira OAuth文章。为了简单起见,请使用basic authentication对您的username:password
进行base64编码,并将其添加(前缀为“基本”)到Authorization
标题。
var encodedAuth = System.Convert.ToBase64String(
System.Text.Encoding.UTF8.GetBytes("username:password")
);
var Client = new HttpClient();
Client.DefaultRequestHeaders.Add("Authorization", "Basic " + encodedAuth);