I am using WCF REST Startkit to create a test REST web service. To test it, I create a simple Console application with HTTPClient (provided by the kit) and HttpResponseMessage to make a request to the REST service. Here are some codes:
HttpClient client = new HttpClient(argsParser.BaseAddress);
HttpResponseMessage resp = client.Get(argsParser.URI);
Console.WriteLine(@"READING DATA FROM {0}{1}",
argsParser.BaseAddress,
argsParser.URI.Length == 0 ? @"" : string.Format(@"/{0}",
argsParse.URI));
resp.EnsureStatusIsSuccessful();
string contentType = resp.Content.ContentType;
Console.WriteLine("CONTENT TYPE: {0}", contentType);
string content = resp.Content.ReadAsString();
Console.WriteLine(
@"CONTENT: {0}", content);
where argsParser is my argument parser class to get base address and URI. It works fine as I said with my REST service in our intranet. However, when I used the test app with a web REST service such as Twitter REST service, I got exceptions.
I think this is caused by my work network settings. BlueCode security has been implemented as an enforcement to all browsers/http requests at work. I have to type in my user/pwd in a prompt window when my browser is accessing to a web REST service like Twitter's first time. After I provide my authentication information, the browser works fine.
So I guess that with HttpClient and HTTPResponseMessage instances created in my console application, I may need to add/attach some authentication information to them. I am not sure what classes or APIs I need to provide the required authentication information?