When sending multi-value cookies, you can use the following method to set multi-value cookies.
C # code
System. Net. HttpWebRequest r = System. Net. HttpWebRequest. Create ("http://www.mengxianhui.com: 8081/B. aspx") as System. Net. HttpWebRequest;
R. headers ["Cookie"] = "Url = http://dotnet.aspx.cc; UserInfo = UserName =" + System. web. httpUtility. urlEncode ("Meng xianhui") + "& UserId = net_lover ";
R. Proxy = null;
System. Net. HttpWebResponse response = r. GetResponse () as System. Net. HttpWebResponse;
This. textBox1.Text = new System. IO. StreamReader (response. GetResponseStream (). ReadToEnd ();
Response. Close ();
Or
C # code
System. Net. CookieCollection ccl = new System. Net. CookieCollection ();
System. Net. CookieContainer cc = new CookieContainer ();
System. net. cookie c = new Cookie ("UserInfo", "UserName =" + System. web. httpUtility. urlEncode ("Meng xianhui") + "& UserId = net_lover ");
C. Domain = "mengxianhui.com ";
Ccl. Add (c );
C = new Cookie ("Url", "http://dotnet.aspx.cc ");
C. Domain = "mengxianhui.com ";
Ccl. Add (c );
Cc. Add (ccl );
System. Net. HttpWebRequest r = System. Net. HttpWebRequest. Create ("http://www.mengxianhui.com: 8081/B. aspx") as System. Net. HttpWebRequest;
R. CookieContainer = cc;
R. Proxy = null;
System. Net. HttpWebResponse response = r. GetResponse () as System. Net. HttpWebResponse;
This. textBox1.Text = new System. IO. StreamReader (response. GetResponseStream (). ReadToEnd ();
Response. Close ();
Acceptor:
ASPX code
<% @ Page Language = "C #" AutoEventWireup = "true" %>
<Script runat = "server">
Protected void Page_Load (object sender, EventArgs e)
{
If (Request. Cookies ["UserInfo"]! = Null)
{
Response. Write ("Cookie:" + System. Environment. NewLine + System. Environment. NewLine );
HttpCookie aCookie = Request. Cookies ["UserInfo"];
Response. Write ("UserName =" + System. Web. HttpUtility. UrlDecode (aCookie ["UserName"]);
Response. Write (System. Environment. NewLine );
Response. Write ("UserId =" + aCookie ["UserId"]);
Response. Write (System. Environment. NewLine );
Response. Write ("Url =" + Request. Cookies ["Url"]. Value );
}
Else
{
Response. Write ("You have not set cookies ");
}
}
</Script>