Jazz Forum Welcome to the Jazz Community Forum Connect and collaborate with IBM Engineering experts and users

Problems posting to REST Services

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();
}

0 votes



7 answers

Permanent link
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?

0 votes


Permanent link
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).

0 votes


Permanent link
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.

0 votes


Permanent link
>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.

0 votes


Permanent link
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.

0 votes


Permanent link
Anybody else taken a look at this? Any ideas?

0 votes


Permanent link
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

0 votes

Your answer

Register or log in 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.

Search context
Follow this question

By Email: 

Once you sign in you will be able to subscribe for any updates here.

By RSS:

Answers
Answers and Comments
Question details
× 10,948

Question asked: May 27 '10, 2:17 p.m.

Question was seen: 6,914 times

Last updated: May 27 '10, 2:17 p.m.

Confirmation Cancel Confirm