So like the title says, I send the bootstrap request and receive 7 cookies back from it. I verified in debugging that first function is getting all 7 cookies, however when Function #2 starts executing, there's only 4 cookies in the collection and the two cookies I actually need are missing (Cookie1 and Cookie2). These functions are part of an ASP.Net project. Is there something I'm missing or do I need to switch to doing the calls asynchronously? One Note, I have used a similar implementation to this for the exact same sequence in another project and didn't have any issues, but that wasn't a ASP project.
How the functions are called:
var cookies = Bootstrap(environmentToWork.BootstrapUri, out errorMsg);
var stepOneCookies = ActivationStepOne(Data1, environmentToWork.ActivateStep1, _activateRequest, out errorMsg, cookies);
Function #1 that gets initial cookies:
private IList<RestResponseCookie> Bootstrap(string uri, out string errorMsg)
{
var client = new RestClient(uri)
{
Timeout = -1
};
IRestRequest request = new RestRequest(Method.POST);
IRestResponse response = client.Execute(request);
errorMsg = string.Empty;
if (!response.IsSuccessful)
errorMsg = "Bootstrap service failed!";
return response.Cookies;
}
Function #2, where cookies are missing:
private IList<RestResponseCookie> ActivationStepOne(string Data1, string uri, string fileName, out string errorMsg, IList<RestResponseCookie> cookies)
{
errorMsg = string.Empty;
var jsonStrings = File.ReadAllText(fileName);
var returnMessage = string.Empty;
var getPolicyDetailsJson = JObject.Parse(jsonStrings);
getPolicyDetailsJson["Data1"] = Data1;
getPolicyDetailsJson["Data2"] = Data2;
getPolicyDetailsJson["Data3"] = Data3.Substring(0, 5);
var client = new RestClient(uri)
{
Timeout = -1
};
var request = new RestRequest(Method.POST);
request.AddHeader("Cookie1", cookies.FirstOrDefault(x => x.Name == "Cookie1").Value);
request.AddParameter(cookies.FirstOrDefault(y => y.Name == "Cookie2").Name, cookies.FirstOrDefault(z => z.Name == "Cookie2").Value, ParameterType.Cookie);
request.AddHeader("Content-Type", "application/json");
request.AddParameter("application/json", getPolicyDetailsJson.ToString(), ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
if (!response.IsSuccessful)
errorMsg = "Activation Step 1 Failed";
return response.Cookies;
}