예제 #1
0
        /// <summary>
        /// 根据微博短地址获取淘宝真实地址及网页数据
        /// </summary>
        /// <param name="weiboshorturl"></param>
        /// <param name="alimamacc"></param>
        /// <param name="tbrealurl"></param>
        /// <returns></returns>
        public static string GetItemResultWithWeiboShortUrl(string weiboshorturl, CookieContainer alimamacc, ref string tbrealurl)
        {
            string tbkurl = "";

            if (weiboshorturl.Contains("s.click.taobao.com"))
            {
                tbkurl = weiboshorturl;
                goto buzhou3;
            }
            //一次跳转,微博短链接 -> 淘宝客短链接
            HttpWebRequest req = (HttpWebRequest)HttpWebRequest.Create(weiboshorturl);

            req.AllowAutoRedirect = false;
            WebResponse rsp = req.GetResponse();

            tbkurl = rsp.Headers["location"];
            req.Abort();
            rsp.Close();
            rsp.Dispose();


            //二次跳转,淘宝客短链接 -> 淘宝客长链接
            req = (HttpWebRequest)HttpWebRequest.Create(tbkurl);
            if (tbkurl.Contains("uland.taobao.com"))
            {
                //string result1 = HttpHelper1.GetHttpsHtml(tbkurl, "", ref tbrealurl);
                return(tbkurl);
            }
            req.AllowAutoRedirect = false;
            req.UserAgent         = "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/45.0.2454.101 Safari/537.36";
            rsp = req.GetResponse();

            tbkurl = rsp.Headers["location"];
            req.Abort();
            rsp.Close();
            rsp.Dispose();
buzhou3:
            //三次跳转,淘宝客长链接 -> 淘宝Item跳转地址
            req = (HttpWebRequest)HttpWebRequest.Create(tbkurl);
            req.AllowAutoRedirect = false;
            req.UserAgent         = "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/45.0.2454.101 Safari/537.36";
            rsp    = req.GetResponse();
            tbkurl = rsp.Headers["location"];
            if (tbkurl == null)
            {
                tbkurl = rsp.ResponseUri.ToString();
            }
            //释放资源
            req.Abort();
            rsp.Close();
            rsp.Dispose();

            //四次跳转,淘宝Item真实地址
            string tu = tbkurl.Replace("https://s.click.taobao.com/t_js?tu=", "");

            tu = HttpUtility.UrlDecode(tu);

            string result = HttpHelper1.GetHttpsHtml(tu, tbkurl, ref tbrealurl);

            return(result);
        }