0

I need to pass all my current page cookies to other server with request:

string url = "http://www.someserver.com/page1.aspx"; // Create a request for the URL. WebRequest request = WebRequest.Create(url); // If required by the server, set the credentials. request.Credentials = CredentialCache.DefaultCredentials; // Get the response. WebResponse response = request.GetResponse(); // Display the status. //Console.WriteLine(((HttpWebResponse)response).StatusDescription); // Get the stream containing content returned by the server. Stream dataStream = response.GetResponseStream(); // Open the stream using a StreamReader for easy access. StreamReader reader = new StreamReader(dataStream); // Read the content. string responseFromServer = reader.ReadToEnd(); // Display the content. Console.WriteLine(responseFromServer); // Clean up the streams and the response. reader.Close(); response.Close(); 

What should I add to this code to read current cookies and pass them to http://www.someserver.com/page1.aspx

Thanks

1 Answer 1

1
((HttpWebRequest)request).Headers[HttpRequestHeader.Cookie] = Request.Headers[HttpRequestHeader.Cookie.ToString()]; 

where obviously the Request variable used here is an ASP.NET HttpRequest instance.

Sign up to request clarification or add additional context in comments.

1 Comment

I tried this, and it did nothing but pass in 1 item into Headers, which was "Cookie" and not all the cookies. Just 1

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.