淘宝客短链接 取 天猫或者淘宝的商品长链接
下面是C#代码
[C#] 纯文本查看 复制代码 private string taobaoduanlianjie(string Url)
{
HttpHelper http = new HttpHelper();
HttpItem item = new HttpItem()
{
URL = Url,//URL 必需项
Method = "get",//URL 可选项 默认为Get
ContentType = "text/html",//返回类型 可选项有默认值
Allowautoredirect = false//默认为False就是不根据重定向自动跳转
};
HttpResult result = http.GetHtml(item);
HttpHelper http2 = new HttpHelper();
HttpItem item2 = new HttpItem()
{
URL = result.Header[HttpResponseHeader.Location],//URL 必需项
Method = "get",//URL 可选项 默认为Get
ContentType = "text/html",//返回类型 可选项有默认值
Allowautoredirect = false,//默认为False就是不根据重定向自动跳转
};
HttpResult result2 = http2.GetHtml(item2);
string t_M = result.Header[HttpResponseHeader.Location].ToString();
string t_js = result2.Header[HttpResponseHeader.Location].ToString();
string et = t_js.Substring(t_js.IndexOf("et%3D") + 5, t_js.Length - (t_js.IndexOf("et%3D") + 5));
string diyibufen = "http" + Between(t_js, "http", "ref%3D") + "ref%3D";
string dierbufen = "%26et%3D" + et;
t_js = diyibufen + dierbufen;
string zuihouyibu_url = System.Web.HttpUtility.UrlDecode(t_M) + "&ref=&et=" + et;
HttpHelper http3 = new HttpHelper();
HttpItem item3 = new HttpItem()
{
URL = zuihouyibu_url,//URL 必需项
Method = "get",//URL 可选项 默认为Get
ContentType = "text/html",//返回类型 可选项有默认值
Allowautoredirect = false,//默认为False就是不根据重定向自动跳转
Referer = t_js,//来源URL 可选项
};
HttpResult result3 = http3.GetHtml(item3);
return result3.RedirectUrl;
}
/// <summary>
/// 取文本中间内容
/// </summary>
/// <param name="str">原文本</param>
/// <param name="leftstr">左边文本</param>
/// <param name="rightstr">右边文本</param>
/// <returns>返回中间文本内容</returns>
public static string Between(string str, string leftstr, string rightstr)
{
int i = str.IndexOf(leftstr) + leftstr.Length;
string temp = str.Substring(i, str.IndexOf(rightstr, i) - i);
return temp;
}
第三次GET,也是取的协议头,商品链接在协议头里,看图片
老大要是还有不明白的,我再追加说明哦!很急哦,老大,帮帮忙
|