1

我在将 http 包发送到网站时遇到了麻烦,在嗅探器中,屏幕截图中的http://data2.floomby.com/files/previews/25_3_2013/KUi91GEdh02qmEM94LQtw.jpgPOST看起来像这样。我认为,有些东西在发送之前混合了我的帖子内容数据,但字符串看起来很正常。这是我的方法代码:postdata

    public ResponseData AdvancedRequest(string method, string url, string postdata, string proxydata, string referer, int timeout)
    {
        var req = WebRequest.Create(url) as HttpWebRequest;
        req.Method = "GET";
        IWebProxy myProxy = new WebProxy(proxydata.Split(':')[0],  Convert.ToInt32(proxydata.Split(':')[1]));
        req.Proxy = null;
        //req.ServicePoint.ConnectionLimit = 1;
        req.ProtocolVersion = HttpVersion.Version10;
        req.KeepAlive = true;
        //req.UserAgent = "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:19.0) Gecko/20100101 Firefox/19.0";
        req.UserAgent = "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:19.0) Gecko/20100101 Firefox/19.0";
        req.AllowAutoRedirect = false;
        req.Timeout = timeout*1000;
        req.ReadWriteTimeout = timeout*1000;
        req.ContentType = "application/x-www-form-urlencoded";
        req.Accept = "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8";
        req.Headers.Add("Accept-Language", "en-US,en;q=0.5");
        //req.Headers.Add("Accept-Charset", "ISO-8859-1,utf-8;q=0.7,*;q=0.3");
        req.Headers.Add("Accept-Encoding", "gzip, deflate");
        //req.Headers.Add("cache-control", "max-age=0");
        req.CookieContainer = _cookies;
        //req.Headers.Add("Keep-Alive", "115");
        //req.Connection = "keepalive";
        if (!String.IsNullOrEmpty(referer))
        {
            req.Referer = referer;
        }

        req.AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate;
        if (method == "POST")
        {
            req.Method = "POST";
            req.ServicePoint.Expect100Continue = false;
            System.Text.Encoding enc = System.Text.Encoding.UTF8;
            var bytedata = enc.GetBytes(postdata);
            req.ContentLength = bytedata.Length;
            //Stream postStream = req.GetRequestStream();
            try
            {
                using (var postStream = req.GetRequestStream())
                {
                    postStream.Write(bytedata, 0, bytedata.Length);
                    postStream.Close();
                }
            }
            catch (WebException except)
            {

            }

        }

        HttpWebResponse resp = (HttpWebResponse)req.GetResponse() as HttpWebResponse;
        this._cookies.Add(resp.Cookies);
        //resp.Close();
        ResponseData rdata = new ResponseData(resp);
        resp.Close();
        return rdata;
        //StreamReader strdr = new StreamReader(resp.GetResponseStream());
        //string response = strdr.ReadToEnd();
        //strdr.Close();

        //return response;
    }

这是正确的帖子数据:

session%5Busername_or_email%5D=LoginHere&session%5Bpassword%5D=PasswordHere&return_to_ssl=true&scribe_log=&redirect_after_login=%2F&authenticity_token=auth_token_here

这是我的错误帖子数据:

session%5Busername_or_email%5D=AsyncCallback&session%5Bpassword%5D=De2zmcc6093&return_to_ssl=true&scribe_log=&redirect_after_login=%2F&authenticity_token=0e67f8df715c79f81a9b2be203848ad7f805b21csession%5Busername_or_email%5D=AsyncCallback&session%5Bpassword%5D=De2zmcc6093&return_to_ssl=true&scribe_log=&redirect_after_login=%2F&authenticity_token=0e67f8df715c79f81a9b2be203848ad7f805b21c

的值为postdata

session%5Busername_or_email%5D=登录&session%5Bpassword%5D=密码&return_to_ssl=true&scribe_log=&redirect_after_login=%2F&authenticity_token=0e67f8df715c79f81a9b2be203848ad7f805b21c

4

0 回答 0