RTC 服务器似乎不喜欢我的 url 请求。我基本上可以在 url 的“主机”部分之后添加我想要的任何内容并获得相同的结果。所以我猜测我所拥有的东西是错误的。根据我上一篇文章的回答,我很确定我从<oslc_cm:simpleQuery><dc:title>Change request queries</dc:title>
标签中的“服务”文件中获得了正确的 url。所以我不确定是否还有其他不喜欢的东西?它不再无法通过身份验证,我现在使用的是基于表单而不是基本的,所以我认为它与身份验证无关。它似乎忽略了任何事情,但仍然知道我的凭据没有错。有任何想法吗?
更新:我也试过用 %3A 交换所有的冒号,因为 Jazz文档在他们的例子中似乎不是特别一致,如果有必要的话。虽然结果相同。
string host = "https://my.host.com:9443/ccm/";
string item = host + "oslc/contexts/_MySp3ci4lK3Y/workitems?" +
"oslc.where=dcterms:identifier=%222494443%22&" +
"oslc.properties=dcterms:title,dcterms:identifier&" +
"oslc.prefix=dcterms=%3Chttp://purl.org/dc/terms/%3E";
Debug.Log("Request");
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(item);
request.Accept = "application/json";
request.Headers.Add("OSLC-Core-Version", "2.0");
WebResponse response = request.GetResponse();
string AuthHeader = response.Headers["X-com-ibm-team-repository-web-auth-msg"];
//check if authentication has failed
if ((AuthHeader != null) && AuthHeader.Equals("authrequired"))
{
Debug.Log("Authentication Required");
HttpWebRequest _formPost = (HttpWebRequest)WebRequest.Create(host + "authenticated/j_security_check"); // Same response without the "authenticated/j_security_check"
_formPost.Method = "POST";
_formPost.Timeout = 30000;
_formPost.Headers.Add("OSLC-Core-Version", "2.0");
_formPost.CookieContainer = request.CookieContainer;
_formPost.Accept = "text/xml";
_formPost.ContentType = "application/x-www-form-urlencoded";
Byte[] _outBuffer = Encoding.UTF8.GetBytes(credentials); //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;
}
else
{
//login successful
// *** Still says AuthRequired here for some reason ***
Debug.Log("Auth Header = " + _rtcAuthHeader);
_formResponse.GetResponseStream().Flush();
_formResponse.Close();
//FormBasedAuth Step3: Resend the request for the protected resource.
response = (HttpWebResponse)request.GetResponse();
}
}
else if (AuthHeader == null)
{
Debug.Log("AuthHeader Null");
}
else
{
Debug.Log("AuthHeader = " + AuthHeader);
}
Debug.Log("Response Stream");
Stream responseStream = response.GetResponseStream();
byte[] buffer = new byte[BufferSize];
int read;
while ((read = responseStream.Read(buffer, 0, buffer.Length)) > 0)
{
// Prints out an HTML Doc rather than a JSON string.
Debug.Log(Encoding.UTF8.GetString(buffer));
}