首页 > Web开发 > 详细

Httprequest 添加Cookie

时间:2017-05-20 11:54:18      阅读:907      评论:0      收藏:0      [点我收藏+]
    string postData = "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

原文:http://www.cnblogs.com/kunlunmountain/p/6881699.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!