(使用C#(我正在尝试验证,但总是失败。我知道我的用户名和密码是正确的。如果这很重要的话,我们可能会使用OSLC 1.0。我不确定,但我在services.xml文件中看到过几次。我所了解的网站使用的是3.0。也许有什么不同?知道我做错了什么吗?
Debug.Log("Authentication Required");
// tried with just j_security_check as well (without "authenticated") as he seems to do both on the site
HttpWebRequest _formPost = (HttpWebRequest)WebRequest.Create(localhost + "authenticated/j_security_check");
_formPost.Method = "POST";
_formPost.Timeout = 30000;
_formPost.CookieContainer = request.CookieContainer;
_formPost.Accept = "text/xml";
_formPost.ContentType = "application/x-www-form-urlencoded";
Byte[] _outBuffer = Encoding.UTF8.GetBytes("j_username=coolcat&j_password=bestPassEvar"); //store in byte buffer
_formPost.ContentLength = _outBuffer.Length;
Stream _str = _formPost.GetRequestStream();
_str.Write(_outBuffer, 0, _outBuffer.Length); //update form
_str.Close();
//FormBasedAuth Step2:submit the login form and get the response from the server
HttpWebResponse _formResponse = (HttpWebResponse)_formPost.GetResponse();
string _rtcAuthHeader = _formResponse.Headers["X-com-ibm-team-repository-web-auth-msg"];
//check if authentication has failed
if ((_rtcAuthHeader != null) && _rtcAuthHeader.Equals("authfailed"))
{
Debug.Log("Authentication Failed");
return;
}
Ugh。我真是个傻瓜。用户名/密码是正确的,但我在使用它之前编码了两次!(在上面的代码中没有看到,因为出于明显的安全原因,我对它进行了硬编码(。
您可以在github存储库中找到一些使用OSLC与基于Jazz的产品通信的示例代码https://github.com/OSLC/lyo-samples.
我发现了这个特别处理表单身份验证的示例代码。https://github.com/OSLC/lyo-samples/blob/master/oslc4j-client-samples/src/main/java/org/eclipse/lyo/oslc4j/client/samples/ERMSample.java
同一文件夹中的许多程序试图连接到不同的Jazz解决方案。