.net 模拟登陆 post https 请求跳转页面

AllowAutoRedirect property is true, the Referer property is set automatically when the request is redirected to another site.">如果 AllowAutoRedirect 属性为 true,则 Referer 属性在请求被重定向到另一个站点时自动设置。

Referer HTTP header, set the Referer property to null.">若要清除 RefererHTTP 标头,请将 Referer 属性设置为 null。
如果设置了  Referer 则 指定到某个站点. 被这东西小坑了一下 涨姿势。

          private bool CheckValidationResult(object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors errors)
          {
               return true; //总是接受安全证书
          }

          private void test()
          {
               ServicePointManager.ServerCertificateValidationCallback = new RemoteCertificateValidationCallback(CheckValidationResult);
               CookieCollection _cookies = null; //后续使用
               var addRess = "https://xxxxxxxxxx";
               var data = "account=xxxxxxx&password=xxxxx";

               HttpWebRequest request = (HttpWebRequest)WebRequest.Create(addRess);
               request.CookieContainer = new CookieContainer();
               request.Timeout = 1000 * 60;
               request.Method = "POST";
               request.ContentType = "application/x-www-form-urlencoded";
               request.AllowAutoRedirect = true;
               request.Referer = addRess;

               byte[] bs = Encoding.UTF8.GetBytes(data);
               HttpWebResponse response = null;
               StreamReader myStreamReader = null;
               Stream myRequestStream = null;
               request.ContentLength = bs.Length;
               string retString = string.Empty;
               try
               {
                    using (myRequestStream = request.GetRequestStream())
                    {
                         myRequestStream.Write(bs, 0, bs.Length);
                         myRequestStream.Close();
                    }
                    response = (HttpWebResponse)request.GetResponse();
                    _cookies = response.Cookies;
                    using (Stream myResponseStream = response.GetResponseStream())
                    {
                         using (myStreamReader = new StreamReader(myResponseStream, Encoding.GetEncoding("BIG5")))
                         {
                              retString = myStreamReader.ReadToEnd();
                         }
                    }
               }
               catch (Exception)
               {

                    throw;
               }
               finally
               {
                    if (myRequestStream != null)
                    {
                         myRequestStream.Close();
                    }
                    if (response != null)
                    {
                         response.Close();
                    }
                    if (myStreamReader != null)
                    {
                         myStreamReader.Close();
                    }
               }
          }
时间: 2024-07-30 22:54:52

.net 模拟登陆 post https 请求跳转页面的相关文章

解决shiro登陆超时ajax请求跳转

使用JQueryEasyUI的时候,普通请求在shrio登陆超时的时候都可以正常跳转,而ajax请求在登陆超时的时候就不跳转,上网找了下资料,都表达的不明确,而且设置一大堆,还得写过滤器.无意中找到JQuery设置全局 AJAX 默认选项.具体代码如下! $.ajaxSetup({     complete:function(XMLHttpRequest,textStatus){           if(textStatus=="parsererror"){             

模拟http或https请求,实现ssl下的bugzilla登录、新增BUG,保持会话以及处理token

1.增加相应httpclient 需要的jar包到工程,如果是maven工程请在pom.xml增加以下配置即可: <dependency> <groupId>org.apache.httpcomponents</groupId> <artifactId>httpclient</artifactId> <version>4.4.1</version></dependency> 2. 新建测试类(完全模拟http请

http模拟登陆及发请求

首先声明下,如果服务端写入的cookie属性是HttpOnly的,程序是不能自动获取cookie的,需要人工登陆网站获取cookie再把cookie写死,如下图所示: http测试工具:http://www.atool.org/httptest.php package com.eshore.ismp.hbinterface.vsop.client.productCancelBatcher; import java.io.BufferedReader; import java.io.IOExcep

PHP实现curl和snoopy类模拟登陆方法

Snoopy.class.php下载 方法/步骤 第一种:使用snoopy类实现模拟登陆 1.在网上下载一个Snoopy.class.php的文件   2.代码实现: <?php set_time_limit(0); require "Snoopy.class.php"; $snoopy=new Snoopy(); $snoopy->referer='你要模拟登陆的域名';//例如:http://www.baidu.com/ $snoopy->agent="

使用httpClient模拟登陆开心网过程中登陆成功但是跳转不成功

package com.haojiahong.test; import java.util.ArrayList; import java.util.List; import org.apache.http.HttpResponse; import org.apache.http.NameValuePair; import org.apache.http.client.ResponseHandler; import org.apache.http.client.entity.UrlEncodedF

PHP-Curl模拟HTTPS请求

话不多说,直接上代码 <?php /** * 模拟post进行url请求 * @param string $url * @param array $postData */ function request_post($url = '', $postData = []) { if (empty($url)) { return false; } if ($postData != []) { $vars = http_build_query($postData, '', '&'); curl_se

httpclient 3.1跳过https请求SSL的验证

一.因为在使用https发送请求的时候会涉及,验证方式.但是这种方式在使用的时候很不方便.特别是在请求外部接口的时候,所以这我写了一个跳过验证的方式.(供参考) 二.加入包,这里用的是commons-httpclient 3.1 的包.一般请求采用最新的httpclient4.5就可以了 <dependency> <groupId>commons-httpclient</groupId> <artifactId>commons-httpclient</

httpclient跳过https请求的验证

一.因为在使用https发送请求的时候会涉及,验证方式.但是这种方式在使用的时候很不方便.特别是在请求外部接口的时候,所以这我写了一个跳过验证的方式.(供参考) 二.加入包,这里用的是commons-httpclient 3.1 的包.一般请求采用最新的httpclient4.5就可以了 <dependency> <groupId>commons-httpclient</groupId> <artifactId>commons-httpclient</

使用C#发送Http 请求实现模拟登陆(以博客园为例)

原文:使用C#发送Http 请求实现模拟登陆(以博客园为例) 模拟登陆的原理很简单,就是发送一个Http 请求服务器获得响应,然后客户端获取到cookie即可实现模拟登陆,比如一些抢票软件的原理无非也是这样模拟客户端的cookie 然后发送请求去抢票,然后12306 本文将演示如何用C# 来实现模拟登陆的,推荐一款工具Fiddler,这是一款监听http 请求的利器.废话不多说,我就以博客园为例来实现模拟登陆.首先我登陆博客园 http://passport.cnblogs.com/login.