首页新闻找找看学习计划

https 与 http 共存时 httpWebRequest 应该如何处理

0
悬赏园豆:40 [已解决问题] 解决于 2012-12-03 13:41
 HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://pinterest.com/login/?next=%2F");
            request.Method = "GET";
            request.CookieContainer = cc;
            HttpWebResponse response = (HttpWebResponse)request.GetResponse();
            string encoding = response.ContentEncoding;
            if (encoding == null || encoding.Length < 1)
            {
                encoding = "UTF-8"; // 默认编码
            }
            StreamReader reader = new StreamReader(response.GetResponseStream(), Encoding.GetEncoding(encoding));
            string data = reader.ReadToEnd();
            string token= RegexMatch(data,@"(?<=csrfmiddlewaretoken' value=')([\s\S]*?)(?=')");
            string ch =RegexMatch(data,@"(?<=_ch' value=')([\s\S]*?)(?=')");
            response.Close();
           
            request = (HttpWebRequest)WebRequest.Create("https://pinterest.com/login/?next=%2Flogin%2F");
            ServicePointManager.ServerCertificateValidationCallback =  new RemoteCertificateValidationCallback(CheckValidationResult);
            request.Method = "POST";
            request.AllowAutoRedirect = true;
            request.PreAuthenticate = true;
            request.Credentials = CredentialCache.DefaultCredentials;
            request.Accept = "image/jpeg, application/x-ms-application, image/gif, application/xaml+xml, image/pjpeg, application/x-ms-xbap, application/vnd.ms-excel, application/vnd.ms-powerpoint, application/msword, */*";
            request.UserAgent = "Mozilla/4.0 (compatible; MSIE 9.0; qdesk 2.5.1270.201; Windows NT 6.1; Trident/5.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; .NET4.0C; .NET4.0E; Alexa Toolbar)";
            request.Referer = "https://pinterest.com/";
            request.ContentType = "application/x-www-form-urlencoded";
            request.CookieContainer = cc;
            data = String.Format("email={0}&password={1}&next=%2F&csrfmiddlewaretoken={2}&_ch={3}", textBox2.Text, textBox3.Text,token,ch);
            request.ContentLength = data.Length;
            StreamWriter writer = new StreamWriter(request.GetRequestStream(), Encoding.ASCII);
            writer.Write(data);
            writer.Flush();
            response = (HttpWebResponse)request.GetResponse();

我 想用HTTPWEBREQUEST方式登录pinterest,可是用HTTPS方式返回的数据总是未登录 求解  谷歌百度想了一下午了

shineme的主页 shineme | 初学一级 | 园豆:29
提问于:2012-11-02 00:58
< >
分享
最佳答案
0

将HttpWebResquest实例的ProtocolVersion属性设置为HttpVersion.Version10试试呢

收获园豆:40
田林九村 | 老鸟四级 |园豆:2367 | 2012-11-02 08:11
其他回答(2)
0
kongyuan0629 | 园豆:207 (菜鸟二级) | 2012-11-02 09:36
0

.net版本问题 换成.net 4.0 就解决了

shineme | 园豆:29 (初学一级) | 2012-12-03 13:41
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册