I started with the following post to create my method: Stack Overflow Post
I created the following method:
public HttpResponseMessage GetStuffFromRest(MyRequest myData)
{
var baseAddress = new Uri(_baseUri);
var requestXML = CreateBody(myData);
var response = new HttpResponseMessage();
var cookieContainer = new CookieContainer();
using (var handler = new HttpClientHandler() { CookieContainer = cookieContainer })
using (HttpClient httpClient = new HttpClient(handler) { BaseAddress = baseAddress })
{
#region Trying Cookie Container
httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", "myUserName");
var c = new Cookie("Cookie", HttpContext.Current.Server.UrlEncode(myData.Cookie));
cookieContainer.Add(baseAddress, c);
response = httpClient.PostAsync(_myMethodUri, new StringContent(requestXML, Encoding.UTF8, "application/xml")).Result;
#endregion
}
return response;
}
myData.Cookie is populated from another rest service that I called and obtained the cookie from.
When I call another web service I am getting a 401 status code back.
I believe it has to do with how I am passing the cookie to the rest service.
How can I verify what exactly my headers contain? (Particularly the cookie)
UPDATE: Rephrased the question.