Invoke Code Exception - The name 'HttpContext' does not exist in the current context

So I figured out why I wasn’t getting the expected outcome. In my initial code I defined these values:

request.AddCookie("Cookie", "Cookie_1=value; JSESSIONID=node0gi4uhegtzmqevx6bn233abhg344007.node0");
request.AddHeader("Content-Type", "application/x-www-form-urlencoded");
request.AddParameter("Payload", payload);

The cookie value is useless and the payload paramenter is wrong, and now I have this:

request.AddHeader("Content-Type", "application/x-www-form-urlencoded");
request.AddParameter("text/xml", payload, ParameterType.RequestBody);

Complete working script:

var client = new RestSharp.RestClient();
client.BaseUrl = new Uri(url);

var request = new RestSharp.RestRequest(RestSharp.Method.POST);

request.AddHeader("Content-Type", "application/x-www-form-urlencoded");
request.AddParameter("text/xml", payload, ParameterType.RequestBody);
client.FollowRedirects=false;

IRestResponse response = client.Execute(request);
cookie = System.Net.WebUtility.UrlDecode(response.Headers.ToList().Find(x => x.Name == "Set-Cookie").Value.ToString());

Everyone, specially to @ptrobot , a huge thank you!

1 Like