It's all about the answers!

Ask a question

Problems posting to REST Services


Brad Shannon (3133) | asked May 27 '10, 2:17 p.m.
I am trying to post to the RTC REST web service and the response I keep getting back is the HTML for the 'Loading...' screen. We are using Basic Auth on our server, and I don't know how to authenticate with the service through my code.

Can anyone help?


Uri address = new Uri("https://rtc01/jazz/oslc/contexts/_yuoM4AuAEd-_tYX4gJSsYA/workitems");

NetworkCredential cred = new NetworkCredential("username", "password");
ICredentials iCred = cred.GetCredential(address, "Basic");

HttpWebRequest request = (HttpWebRequest)WebRequest.Create(address);
request.Credentials = iCred;
request.PreAuthenticate = true;

request.Accept = "text/xml";
request.Method = "POST";
request.ContentType = "application/x-oslc-cm-change-request+xml";

XmlDocument xmlDoc = new XmlDocument();
xmlDoc.LoadXml(xmlStr);

byte[] byteData = UTF8Encoding.UTF8.GetBytes(xmlDoc.ToString());
request.ContentLength = byteData.Length;

using (Stream postStream = request.GetRequestStream())
{
postStream.Write(byteData, 0, byteData.Length);
}

using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())
{
StreamReader reader = new StreamReader(response.GetResponseStream());

string output = reader.ReadToEnd();
}

7 answers



permanent link
Patrick Streule (4.9k21) | answered Jun 18 '10, 1:05 p.m.
JAZZ DEVELOPER
On 6/17/10 10:53 PM, philipereed wrote:
Anybody else taken a look at this? Any ideas?


It seems to be a problem specific to the .NET implementation, as we
haven't seen this issue with other languages yet. Without debugging your
implementation, it is hard to tell what goes wrong.

--
Regards,
Patrick
Jazz Work Item Team

permanent link
Philip Reed (3654) | answered Jun 17 '10, 4:45 p.m.
Anybody else taken a look at this? Any ideas?

permanent link
Philip Reed (3654) | answered Jun 03 '10, 3:35 p.m.
Here's what I know so far.

- Server traces show the request POSTed but with no associated session id. However, client traces show the session id on the request immediately before the send. As a result, a new session is created and authentication is requested.

- If I leave out the body on the POST, server traces show the request WITH the correct session id and I get an error for invalid content (makes sense).

- The problem only occurs when I execute my .NET client code in run mode or step straight through in the debugger. If I pause for 10 seconds on the actual req.GetResponse() method (C#) it works correctly.

My assumption is that this narrows the problem to three areas:

1) The .NET runtime for the HttpWebRequest method
2) The tomcat coyote http runtime
3) The RTC application

BTW, a GET to the factory URL successfully returns a list of workitems.

permanent link
Curtis d'Entremont (1.3k3) | answered Jun 02 '10, 2:18 p.m.
FORUM MODERATOR / JAZZ DEVELOPER
>Surprisingly, if I pause in the debugger for about 10 seconds before executing the actual send of the request it works

That's because it knows you're debugging ;-)

I think we need help from someone on Work Items to debug this one. I'm also curious about this loading page though. Could you check whether there is a 302 redirect happening here (and silently being followed by your HTTP client), and also what exactly is in the HTML page ? It sounds like it's trying to load the Web UI.

The only reason I can think of why this would be happening is that the OSLC service does content negotiation based on your accept header and thinks the most appropriate response for you is the Web UI. But I'm just guessing.

permanent link
Philip Reed (3654) | answered Jun 02 '10, 1:49 p.m.
Interesting...I've been working on this the past few days as well but from .NET client code. I get the same results using both BASIC and FORM authentication.

Everything else works using the same send/receive code and credentials except the POST to the work item factory. I can make it work from Poster once I've authenticated correctly, using the fully-qualified host name, but not from inside my code.

Surprisingly, if I pause in the debugger for about 10 seconds before executing the actual send of the request it works, but not if I execute in run mode or step straight through in the debugger.

permanent link
Curtis d'Entremont (1.3k3) | answered May 31 '10, 5:18 p.m.
FORUM MODERATOR / JAZZ DEVELOPER
It looks like you're either getting some type of login page, which would mean the server is not using basic auth, or the service is not returning the right thing.

Can you try opening it in a browser to confirm that the server is sending back the right thing and that it's indeed using basic auth? If it's using basic auth, the browser will typically open a native window popup with username and password fields (not an HTML dialog).

permanent link
Brad Shannon (3133) | answered May 28 '10, 10:16 a.m.
Ok, I've tried posting to the service from the Poster Firefox extension and the response I get back is still the HTML for the 'Loading...' screen.

Does anyone here know anything about the web services? Am I on the wrong forum?

Your answer


Register or to post your answer.


Dashboards and work items are no longer publicly available, so some links may be invalid. We now provide similar information through other means. Learn more here.