首页 > 代码库 > Httprequest 添加Cookie

Httprequest 添加Cookie

    string postData = http://www.mamicode.com/"Inputs={\"BarCode\":\"" + barCode + "\"}"; // 要发放的数据 
                //var str = JsonConvert.SerializeObject(postData);
                byte[] byteArray = Encoding.UTF8.GetBytes(postData);

                HttpWebRequest objWebRequest = (HttpWebRequest)WebRequest.Create("http://180.96.21.213:8890/action.ashx?action=IndexDetailInfosUrl");
                objWebRequest.Method = "POST";
                objWebRequest.ContentType = "application/x-www-form-urlencoded;charset=UTF-8";
                objWebRequest.ContentLength = byteArray.Length;
                objWebRequest.Headers.Add("Cookie", "companyid=XZGH");
                //objWebRequest.CookieContainer = myCookieContainer;
                Stream newStream = objWebRequest.GetRequestStream();
                newStream.Write(byteArray, 0, byteArray.Length); //写入参数 
                newStream.Close();

                HttpWebResponse response = (HttpWebResponse)objWebRequest.GetResponse();
                StreamReader sr = new StreamReader(response.GetResponseStream(), Encoding.UTF8);
                string textResponse = sr.ReadToEnd(); // 返回的数据
                return textResponse;

 

Httprequest 添加Cookie