码迷,mamicode.com
首页 > Web开发 > 详细

Httprequest 添加Cookie

时间:2017-05-20 12:27:00      阅读:253      评论:0      收藏:0      [点我收藏+]

标签:news   class   requests   bre   action   urlencode   web   post   tle   

    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

标签:news   class   requests   bre   action   urlencode   web   post   tle   

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!