1967 lines
93 KiB
C#
1967 lines
93 KiB
C#
using AllBase;
|
|
using CefSharp;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Collections.Specialized;
|
|
using System.IO;
|
|
using System.IO.Compression;
|
|
using System.Linq;
|
|
using System.Net;
|
|
using System.Text;
|
|
using System.Threading;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace Work
|
|
{
|
|
public class GetPostTaobaoHtml
|
|
{
|
|
|
|
public static bool DownLoadImage(string url, out byte[] b)
|
|
{
|
|
string mainDomain = GetHtml.GetMainDomain(GetHtml.GetDomain(url));
|
|
string cookies = "";
|
|
if (BaseClass.CookiesAllString.ContainsKey(mainDomain))
|
|
cookies = BaseClass.CookiesAllString[mainDomain];
|
|
return DownLoadImage(url, out b, cookies);
|
|
}
|
|
|
|
public static bool DownLoadImage(string url, out byte[] b, string cookies)
|
|
{
|
|
if (!string.IsNullOrEmpty(url) && url.Length > 2 && url.Substring(0, 2) == "//")
|
|
url = "http:" + url;
|
|
string refere = url.Contains("yangkeduo.com")
|
|
? BaseClass.NewUrl+"/"
|
|
: "https://detail.tmall.com/item.htm?spm=a230r.1.14.37.51edc9e4PYsBpF&id=35689836013&ns=1&abbucket=15";
|
|
b = new byte[0];
|
|
int time = 0;
|
|
Again:
|
|
try
|
|
{
|
|
string userAgent = BaseClass.ChromeUserAgent;
|
|
WebClientx wb = new WebClientx();
|
|
if (string.IsNullOrEmpty(cookies))
|
|
{
|
|
string mainDomain = GetHtml.GetMainDomain(GetHtml.GetDomain(url));
|
|
if (BaseClass.CookiesAllString.ContainsKey(mainDomain))
|
|
cookies = BaseClass.CookiesAllString[mainDomain];
|
|
}
|
|
//wb.IsDelete = true;
|
|
wb.Timeout = 30;
|
|
wb.AllowAutoRedirect = true;
|
|
wb.Proxy = null;
|
|
wb.Headers.Add("Accept", "image/webp,image/*,*/*;q=0.8");
|
|
wb.Headers.Add("Accept-Encoding", "gzip,deflate");
|
|
wb.Headers.Add("Accept-Language", "zh-CN,zh;q=0.8");
|
|
wb.Headers.Add("User-Agent", userAgent);
|
|
//wb.Headers.Add("Content-Type", "image/jpeg");
|
|
if (!string.IsNullOrEmpty(refere))
|
|
wb.Headers.Add("Referer", refere);
|
|
if (!string.IsNullOrEmpty(cookies))
|
|
wb.Headers.Add("Cookie", cookies);
|
|
b = wb.DownloadData(url);
|
|
return true;
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
if (e.Message.Contains("404"))
|
|
return false;
|
|
if (time < 4)
|
|
{
|
|
time++;
|
|
Thread.Sleep(1000 * time + 1000);
|
|
goto Again;
|
|
}
|
|
}
|
|
return false;
|
|
}
|
|
|
|
public static string UploadTaobaoPic(string url, string refere, bool isUtf8, string cookies)
|
|
{
|
|
return UploadTaobaoPost(url, refere, isUtf8, "", false, cookies);
|
|
}
|
|
public static string UploadTaobaoDelete(string url, string refere, bool isUtf8, string data, bool isPost)
|
|
{
|
|
try
|
|
{
|
|
//string cookies = string.IsNullOrEmpty(BaseClass.ChromeCookies) ? IECookies.GetCookieByWebBrowser(url) : BaseClass.ChromeCookies;
|
|
//string userAgent = string.IsNullOrEmpty(BaseClass.ChromeUserAgent) ? BaseClass.UserAgent : BaseClass.ChromeUserAgent;
|
|
string cookies = BaseClass.ChromeCookies;
|
|
if (url.Contains(".yangkeduo.com"))
|
|
cookies = BaseClass.CookiesAllString["yangkeduo.com"];
|
|
string userAgent = BaseClass.ChromeUserAgent;
|
|
WebClientx wb = new WebClientx();
|
|
wb.IsDelete = true;
|
|
wb.Timeout = 30;
|
|
wb.Proxy = null;
|
|
wb.AllowAutoRedirect = true;
|
|
wb.Headers.Add("Accept", "*/*");
|
|
wb.Headers.Add("Accept-Encoding", "gzip,deflate");
|
|
wb.Headers.Add("Accept-Language", "zh-CN,zh;q=0.8");
|
|
wb.Headers.Add("User-Agent", userAgent);
|
|
wb.Headers.Add("Content-Type", "application/x-www-form-urlencoded;charset=UTF-8");
|
|
if (!string.IsNullOrEmpty(cookies) && cookies.Contains("PDDAccessToken") && BaseClass.CookiesAll.ContainsKey("yangkeduo.com") && BaseClass.CookiesAll["yangkeduo.com"].ContainsKey("PDDAccessToken"))
|
|
wb.Headers.Add("accesstoken", BaseClass.CookiesAll["yangkeduo.com"]["PDDAccessToken"]);
|
|
wb.Proxy = null;
|
|
if (!string.IsNullOrEmpty(refere))
|
|
wb.Headers.Add("Referer", refere);
|
|
if (!string.IsNullOrEmpty(cookies))
|
|
wb.Headers.Add("Cookie", cookies);
|
|
//wb.Proxy = null;
|
|
string rehead = wb.Headers.ToString();
|
|
var encode = isUtf8 ? Encoding.UTF8 : Encoding.GetEncoding("gbk");
|
|
byte[] b, postData = encode.GetBytes(data);
|
|
string html, head;
|
|
try
|
|
{
|
|
if (string.IsNullOrEmpty(data) && !isPost)
|
|
{
|
|
b = wb.DownloadData(url);
|
|
}
|
|
else
|
|
{
|
|
wb.Headers.Add("ContentLength", postData.Length.ToString());
|
|
b = wb.UploadData(url, "POST", postData);
|
|
}
|
|
html = encode.GetString(b);
|
|
|
|
string c = BaseRegex.GetMatchRegexString(wb.ResponseHeaders["Content-Type"], "charset\\s*=\\s*(\\S+)");
|
|
if (!string.IsNullOrEmpty(c))
|
|
{
|
|
c = c.Trim().ToLower().Replace("utf8", "utf-8");
|
|
}
|
|
if (string.IsNullOrEmpty(c))
|
|
c = BaseRegex.GetMatchRegexString(html, @"<meta [^>]*?charset=[""']*([\w-]+)[""']*");
|
|
if (!string.IsNullOrEmpty(c))
|
|
{
|
|
if (c.IndexOf("'") > -1)
|
|
c = c.Substring(0, c.IndexOf("'"));
|
|
if (c.IndexOf("\"") > -1)
|
|
c = c.Substring(0, c.IndexOf("\""));
|
|
if (c.IndexOf(" ") > -1)
|
|
c = c.Substring(0, c.IndexOf(" "));
|
|
if (c.IndexOf(">") > -1)
|
|
c = c.Substring(0, c.IndexOf(">"));
|
|
if (!string.IsNullOrEmpty(c))
|
|
html = Encoding.GetEncoding(c).GetString(b);
|
|
}
|
|
head = wb.ResponseHeaders.ToString();
|
|
}
|
|
catch (Exception ee)
|
|
{
|
|
html = "提交错误:" + ee.Message;
|
|
head = "";
|
|
}
|
|
return GetHtml.Decode(html);
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
LogSave.Add("访问网址错误:" + url + " " + e.Message);
|
|
return "";
|
|
}
|
|
}
|
|
|
|
public static string UploadTaobaoH5(string url, string refere, bool isUtf8, string cookies)
|
|
{
|
|
cookies = BaseClass.IeFormCookies;
|
|
return UploadTaobaoPostH5(url, refere, isUtf8, "", false, cookies);
|
|
}
|
|
public static string UploadTaobaoPostH5(string url, string refere, bool isUtf8, string data, bool isPost,
|
|
string cookies)
|
|
{
|
|
bool againt = false;
|
|
try
|
|
{
|
|
Againt:
|
|
string userAgent = BaseClass.ChromeUserAgent;
|
|
WebClientx wb = new WebClientx();
|
|
wb.Timeout = 30;
|
|
wb.AllowAutoRedirect = true;
|
|
wb.Headers.Add("Accept", "application/json, text/javascript, */*; q=0.01");
|
|
wb.Headers.Add("X-Requested-With", "XMLHttpRequest");
|
|
wb.Headers.Add("Accept-Encoding", "gzip,deflate");
|
|
if (url.Contains("gy.taobao.com"))
|
|
wb.Headers.Add("Origin", "https://gy.taobao.com");
|
|
if (url.Contains("mms.pinduoduo.com"))
|
|
wb.Headers.Add("Origin", "http://mms.pinduoduo.com");
|
|
//if (url.Contains("fuwu.pinduoduo.com"))
|
|
// wb.Headers.Add("Origin", "https://fuwu.pinduoduo.com");
|
|
wb.Headers.Add("Accept-Language", "zh-cn,zh;q=0.8,en-us;q=0.5,en;q=0.3");
|
|
//userAgent = "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/67.0.3396.79 Safari/537.36";
|
|
wb.Headers.Add("User-Agent", userAgent);
|
|
string xtoken = BaseRegex.GetMatchRegexString(ref cookies, "XSRF-TOKEN=([\\s\\S]+?);");
|
|
if (!string.IsNullOrEmpty(xtoken))
|
|
{
|
|
wb.Headers.Add("X-XSRF-TOKEN", xtoken);
|
|
}
|
|
wb.Proxy = null;
|
|
if (!string.IsNullOrEmpty(refere))
|
|
wb.Headers.Add("Referer", refere);
|
|
if (!string.IsNullOrEmpty(cookies))
|
|
wb.Headers.Add("Cookie", cookies);
|
|
string rehead = wb.Headers.ToString();
|
|
var encode = isUtf8 ? Encoding.UTF8 : Encoding.GetEncoding("gbk");
|
|
byte[] b, postData = encode.GetBytes(data);
|
|
string html, head;
|
|
try
|
|
{
|
|
if (string.IsNullOrEmpty(data) && !isPost)
|
|
{
|
|
b = wb.DownloadData(url);
|
|
}
|
|
else
|
|
{
|
|
if (isPost || url.Contains("taobao.com") || url.Contains("1688.com"))
|
|
{
|
|
wb.Headers.Add("Content-Type", "application/x-www-form-urlencoded");
|
|
}
|
|
else
|
|
{
|
|
wb.Headers.Add("Content-Type", "application/json; charset=" + (isUtf8 ? "UTF-8" : "gbk"));
|
|
}
|
|
wb.Headers.Add("ContentLength", postData.Length.ToString());
|
|
b = wb.UploadData(url, "POST", postData);
|
|
}
|
|
html = encode.GetString(b);
|
|
|
|
string c = BaseRegex.GetMatchRegexString(wb.ResponseHeaders["Content-Type"], "charset\\s*=\\s*(\\S+)");
|
|
if (!string.IsNullOrEmpty(c))
|
|
{
|
|
c = c.Trim().ToLower().Replace("utf8", "utf-8");
|
|
}
|
|
if (string.IsNullOrEmpty(c))
|
|
c = BaseRegex.GetMatchRegexString(html, @"<meta [^>]*?charset=[""']*([\w-]+)[""']*");
|
|
if (!string.IsNullOrEmpty(c))
|
|
{
|
|
if (c.IndexOf("'") > -1)
|
|
c = c.Substring(0, c.IndexOf("'"));
|
|
if (c.IndexOf("\"") > -1)
|
|
c = c.Substring(0, c.IndexOf("\""));
|
|
if (c.IndexOf(" ") > -1)
|
|
c = c.Substring(0, c.IndexOf(" "));
|
|
if (c.IndexOf(">") > -1)
|
|
c = c.Substring(0, c.IndexOf(">"));
|
|
if (!string.IsNullOrEmpty(c))
|
|
html = Encoding.GetEncoding(c).GetString(b);
|
|
}
|
|
head = wb.ResponseHeaders.ToString();
|
|
//string lo= response.Headers["Location"];
|
|
}
|
|
catch (Exception ee)
|
|
{
|
|
html = "提交错误:" + ee.Message;
|
|
head = "";
|
|
if (!againt)
|
|
{
|
|
againt = true;
|
|
Thread.Sleep(10 * 1000);
|
|
goto Againt;
|
|
}
|
|
}
|
|
return GetHtml.Decode(html);
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
LogSave.Add("访问网址错误:" + url + " " + e.Message);
|
|
return "";
|
|
}
|
|
|
|
}
|
|
public static string HttpPostData(string url, string fileName, byte[] file, string referer, string cookies)
|
|
{
|
|
bool falg = true;
|
|
Again:
|
|
if (string.IsNullOrEmpty(cookies))
|
|
return "";
|
|
var webRequest = (HttpWebRequest)WebRequest.Create(url);
|
|
// 边界符
|
|
var boundary = "----WebKitFormBoundary3nmMkweghIBnMXSD";
|
|
// 设置属性
|
|
webRequest.KeepAlive = true;
|
|
webRequest.Method = "POST";
|
|
webRequest.ContentType = "multipart/form-data; boundary=" + boundary;
|
|
webRequest.Referer = referer;
|
|
webRequest.UserAgent = "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.198 Safari/537.36";
|
|
webRequest.Accept = "*/*";
|
|
webRequest.Headers.Add("Origin", @"https://fxg.jinritemai.com");
|
|
webRequest.Headers.Add("Sec-Fetch-Site", @"same-origin");
|
|
webRequest.Headers.Add("Sec-Fetch-Mode", @"cors");
|
|
webRequest.Headers.Add("Sec-Fetch-Dest", @"empty");
|
|
webRequest.Headers.Set(HttpRequestHeader.AcceptEncoding, "gzip, deflate");
|
|
webRequest.Headers.Set(HttpRequestHeader.AcceptLanguage, "zh-CN,zh;q=0.9");
|
|
webRequest.Headers.Set(HttpRequestHeader.Cookie, cookies);
|
|
var memStream = new MemoryStream();
|
|
// 边界符
|
|
var beginBoundary = Encoding.ASCII.GetBytes("--" + boundary + "\r\n");
|
|
// 最后的结束符
|
|
var endBoundary = Encoding.ASCII.GetBytes("\r\n--" + boundary + "--");
|
|
// 写入文件
|
|
string filePartHeader =
|
|
"Content-Disposition: form-data; name=\"{0}\"; filename=\"{1}\"\r\n" +
|
|
"Content-Type: image/jpeg\r\n\r\n";
|
|
|
|
var header = string.Format(filePartHeader, "image[0]", fileName);
|
|
var headerbytes = Encoding.UTF8.GetBytes(header);
|
|
memStream.Write(beginBoundary, 0, beginBoundary.Length);
|
|
memStream.Write(headerbytes, 0, headerbytes.Length);
|
|
memStream.Write(file, 0, file.Length);
|
|
// 写入最后的结束边界符
|
|
memStream.Write(endBoundary, 0, endBoundary.Length);
|
|
webRequest.ContentLength = memStream.Length;
|
|
using (Stream stream = webRequest.GetRequestStream())
|
|
{
|
|
memStream.WriteTo(stream);
|
|
}
|
|
string responseText = "";
|
|
var httpWebResponse = (HttpWebResponse)webRequest.GetResponse();
|
|
|
|
if (httpWebResponse != null)
|
|
{
|
|
if (string.IsNullOrEmpty(responseText))
|
|
responseText = ReadResponse(httpWebResponse);
|
|
httpWebResponse.Close();
|
|
}
|
|
if (responseText.Contains("\"success\":false") && falg)
|
|
{
|
|
falg = false;
|
|
goto Again;
|
|
}
|
|
return responseText;
|
|
}
|
|
|
|
public static string ReadResponse(HttpWebResponse response)
|
|
{
|
|
using (Stream responseStream = response.GetResponseStream())
|
|
{
|
|
Stream streamToRead = responseStream;
|
|
if (response.ContentEncoding.ToLower().Contains("gzip"))
|
|
{
|
|
streamToRead = new GZipStream(streamToRead, CompressionMode.Decompress);
|
|
}
|
|
else if (response.ContentEncoding.ToLower().Contains("deflate"))
|
|
{
|
|
streamToRead = new DeflateStream(streamToRead, CompressionMode.Decompress);
|
|
}
|
|
|
|
using (StreamReader streamReader = new StreamReader(streamToRead, Encoding.UTF8))
|
|
{
|
|
return streamReader.ReadToEnd();
|
|
}
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// GET数据
|
|
/// </summary>
|
|
/// <param name="url">网址</param>
|
|
/// <param name="refere">来源</param>
|
|
/// <param name="isUtf8">编码是否为UTF-8</param>
|
|
/// <returns></returns>
|
|
public static string UploadTaobao(string url, string refere, bool isUtf8)
|
|
{
|
|
string cookies = GetCookies(url, "");
|
|
return UploadTaobaoPost(url, refere, isUtf8, "", false, cookies);
|
|
}
|
|
public static string UploadTaobaoTokenx(string url, string refere, bool isUtf8)
|
|
{
|
|
return UploadTaobaoPostToken(url, refere, isUtf8, "", false, "");
|
|
}
|
|
public static string UploadTaobaoPostToken(string url, string refere, bool isUtf8, string data, bool isPost, string cookies)
|
|
{
|
|
try
|
|
{
|
|
cookies = GetCookies(url, cookies);
|
|
string userAgent = BaseClass.ChromeUserAgent;
|
|
WebClientx wb = new WebClientx();
|
|
wb.Timeout = 30;
|
|
wb.AllowAutoRedirect = true;
|
|
wb.Headers.Add("Accept", "application/json, text/javascript, */*; q=0.01");
|
|
wb.Headers.Add("X-Requested-With", "XMLHttpRequest");
|
|
wb.Headers.Add("Accept-Encoding", "gzip,deflate");
|
|
wb.Headers.Add("dnt", "1");
|
|
if (!string.IsNullOrEmpty(cookies) && cookies.Contains("PDDAccessToken"))
|
|
{
|
|
wb.Headers.Add("accesstoken", BaseRegex.GetMatchRegexString(ref cookies, "PDDAccessToken=([^:]+?);"));
|
|
}
|
|
else
|
|
{
|
|
if (!string.IsNullOrEmpty(cookies) && cookies.Contains("PDDAccessToken") && BaseClass.CookiesAll.ContainsKey("yangkeduo.com") && BaseClass.CookiesAll["yangkeduo.com"].ContainsKey("PDDAccessToken"))
|
|
wb.Headers.Add("accesstoken", BaseClass.CookiesAll["yangkeduo.com"]["PDDAccessToken"]);
|
|
if (!string.IsNullOrEmpty(cookies) && url.Contains("api.pinduoduo.com"))
|
|
{
|
|
wb.Headers.Add("accesstoken", BaseClass.CookiesAll["yangkeduo.com"]["PDDAccessToken"]);
|
|
}
|
|
}
|
|
|
|
wb.Headers.Add("Accept-Language", "zh-cn,zh;q=0.8,en-us;q=0.5,en;q=0.3");
|
|
if (url.Contains("buyertrade.taobao.com"))
|
|
wb.Headers.Add("origin", "https://buyertrade.taobao.com");
|
|
wb.Headers.Add("User-Agent", userAgent);
|
|
wb.Proxy = null;
|
|
if (!string.IsNullOrEmpty(refere))
|
|
wb.Headers.Add("Referer", refere);
|
|
if (!string.IsNullOrEmpty(cookies))
|
|
wb.Headers.Add("Cookie", cookies);
|
|
//wb.Proxy = null;
|
|
|
|
var encode = isUtf8 ? Encoding.UTF8 : Encoding.GetEncoding("gbk");
|
|
byte[] b, postData = encode.GetBytes(data);
|
|
string html, head;
|
|
try
|
|
{
|
|
if (string.IsNullOrEmpty(data) && !isPost)
|
|
{
|
|
b = wb.DownloadData(url);
|
|
}
|
|
else
|
|
{
|
|
if (isPost || url.Contains("taobao.com") || url.Contains("1688.com"))
|
|
{
|
|
wb.Headers.Add("Content-Type", "application/x-www-form-urlencoded");
|
|
}
|
|
else
|
|
{
|
|
wb.Headers.Add("Content-Type", "application/json; charset=" + (isUtf8 ? "UTF-8" : "gbk"));
|
|
}
|
|
wb.Headers.Add("ContentLength", postData.Length.ToString());
|
|
string rehead = wb.Headers.ToString();
|
|
b = wb.UploadData(url, "POST", postData);
|
|
}
|
|
html = encode.GetString(b);
|
|
string c = BaseRegex.GetMatchRegexString(wb.ResponseHeaders["Content-Type"], "charset\\s*=\\s*(\\S+)");
|
|
if (!string.IsNullOrEmpty(c))
|
|
{
|
|
c = c.Trim().ToLower().Replace("utf8", "utf-8");
|
|
}
|
|
if (string.IsNullOrEmpty(c))
|
|
c = BaseRegex.GetMatchRegexString(html, @"<meta [^>]*?charset=[""']*([\w-]+)[""']*");
|
|
if (!string.IsNullOrEmpty(c))
|
|
{
|
|
if (c.IndexOf("'") > -1)
|
|
c = c.Substring(0, c.IndexOf("'"));
|
|
if (c.IndexOf("\"") > -1)
|
|
c = c.Substring(0, c.IndexOf("\""));
|
|
if (c.IndexOf(" ") > -1)
|
|
c = c.Substring(0, c.IndexOf(" "));
|
|
if (c.IndexOf(">") > -1)
|
|
c = c.Substring(0, c.IndexOf(">"));
|
|
if (!string.IsNullOrEmpty(c))
|
|
html = Encoding.GetEncoding(c).GetString(b);
|
|
}
|
|
head = wb.ResponseHeaders.ToString();
|
|
if (url.Contains("api=mtop.user.getUserSimple") && head.Contains("_m_h5_tk="))
|
|
html = wb.ResponseHeaders["Set-Cookie"];
|
|
}
|
|
catch (Exception ee)
|
|
{
|
|
html = "提交错误:" + ee.Message;
|
|
head = "";
|
|
}
|
|
return GetHtml.Decode(html);
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
LogSave.Add("访问网址错误:" + url + " " + e.Message);
|
|
return "";
|
|
}
|
|
}
|
|
public static string UploadTaobao(string url, string refere, bool isUtf8, string cookies)
|
|
{
|
|
return UploadTaobaoPost(url, refere, isUtf8, "", false, cookies);
|
|
}
|
|
|
|
public static string GetCookies(string url, string cookies)
|
|
{
|
|
if (!string.IsNullOrEmpty(cookies))
|
|
return cookies;
|
|
string mainDomain = GetHtml.GetMainDomain(GetHtml.GetDomain(url));
|
|
if (BaseClass.CookiesAllString.ContainsKey(mainDomain))
|
|
cookies = BaseClass.CookiesAllString[mainDomain];
|
|
return cookies;
|
|
}
|
|
|
|
public static string UploadTaobaoToken(string url, string refere, bool isUtf8)
|
|
{
|
|
string cookies = GetCookies(url, "");
|
|
return UploadTaobaoTokenPost(url, refere, isUtf8, "", false, cookies);
|
|
}
|
|
public static string UploadTaobaoTokenPost(string url, string refere, bool isUtf8, string data, bool isPost, string cookies)
|
|
{
|
|
try
|
|
{
|
|
string userAgent = BaseClass.ChromeUserAgent;
|
|
WebClientx wb = new WebClientx();
|
|
wb.Timeout = 30;
|
|
wb.AllowAutoRedirect = true;
|
|
wb.Headers.Add("Accept", "application/json, text/javascript, */*; q=0.01");
|
|
wb.Headers.Add("X-Requested-With", "XMLHttpRequest");
|
|
wb.Headers.Add("Accept-Encoding", "gzip,deflate");
|
|
wb.Headers.Add("dnt", "1");
|
|
if (!string.IsNullOrEmpty(cookies) && cookies.Contains("PDDAccessToken") && BaseClass.CookiesAll.ContainsKey("yangkeduo.com") && BaseClass.CookiesAll["yangkeduo.com"].ContainsKey("PDDAccessToken"))
|
|
wb.Headers.Add("accesstoken", BaseClass.CookiesAll["yangkeduo.com"]["PDDAccessToken"]);
|
|
if (!string.IsNullOrEmpty(cookies) && url.Contains("api.pinduoduo.com"))
|
|
{
|
|
wb.Headers.Add("accesstoken", BaseClass.CookiesAll["yangkeduo.com"]["PDDAccessToken"]);
|
|
}
|
|
wb.Headers.Add("Accept-Language", "zh-cn,zh;q=0.8,en-us;q=0.5,en;q=0.3");
|
|
if (url.Contains("buyertrade.taobao.com"))
|
|
wb.Headers.Add("origin", "https://buyertrade.taobao.com");
|
|
wb.Headers.Add("User-Agent", userAgent);
|
|
wb.Proxy = null;
|
|
if (!string.IsNullOrEmpty(refere))
|
|
wb.Headers.Add("Referer", refere);
|
|
if (!string.IsNullOrEmpty(cookies))
|
|
wb.Headers.Add("Cookie", cookies);
|
|
//wb.Proxy = null;
|
|
|
|
var encode = isUtf8 ? Encoding.UTF8 : Encoding.GetEncoding("gbk");
|
|
byte[] b, postData = encode.GetBytes(data);
|
|
string html, head;
|
|
try
|
|
{
|
|
if (string.IsNullOrEmpty(data) && !isPost)
|
|
{
|
|
b = wb.DownloadData(url);
|
|
}
|
|
else
|
|
{
|
|
if (isPost || url.Contains("taobao.com") || url.Contains("1688.com"))
|
|
{
|
|
wb.Headers.Add("Content-Type", "application/x-www-form-urlencoded");
|
|
}
|
|
else
|
|
{
|
|
wb.Headers.Add("Content-Type", "application/json; charset=" + (isUtf8 ? "UTF-8" : "gbk"));
|
|
}
|
|
wb.Headers.Add("ContentLength", postData.Length.ToString());
|
|
string rehead = wb.Headers.ToString();
|
|
b = wb.UploadData(url, "POST", postData);
|
|
}
|
|
html = encode.GetString(b);
|
|
string c = BaseRegex.GetMatchRegexString(wb.ResponseHeaders["Content-Type"], "charset\\s*=\\s*(\\S+)");
|
|
if (!string.IsNullOrEmpty(c))
|
|
{
|
|
c = c.Trim().ToLower().Replace("utf8", "utf-8");
|
|
}
|
|
if (string.IsNullOrEmpty(c))
|
|
c = BaseRegex.GetMatchRegexString(html, @"<meta [^>]*?charset=[""']*([\w-]+)[""']*");
|
|
if (!string.IsNullOrEmpty(c))
|
|
{
|
|
if (c.IndexOf("'") > -1)
|
|
c = c.Substring(0, c.IndexOf("'"));
|
|
if (c.IndexOf("\"") > -1)
|
|
c = c.Substring(0, c.IndexOf("\""));
|
|
if (c.IndexOf(" ") > -1)
|
|
c = c.Substring(0, c.IndexOf(" "));
|
|
if (c.IndexOf(">") > -1)
|
|
c = c.Substring(0, c.IndexOf(">"));
|
|
if (!string.IsNullOrEmpty(c))
|
|
html = Encoding.GetEncoding(c).GetString(b);
|
|
}
|
|
head = wb.ResponseHeaders.ToString();
|
|
if (url.Contains("api=mtop.user.getUserSimple") && head.Contains("_m_h5_tk="))
|
|
html = wb.ResponseHeaders["Set-Cookie"];
|
|
}
|
|
catch (Exception ee)
|
|
{
|
|
html = "提交错误:" + ee.Message;
|
|
head = "";
|
|
}
|
|
return GetHtml.Decode(html);
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
LogSave.Add("访问网址错误:" + url + " " + e.Message);
|
|
return "";
|
|
}
|
|
}
|
|
|
|
public static string UploadTaobaoPost(string url, string refere, bool isUtf8, string data)
|
|
{
|
|
string cookies = GetCookies(url, "");
|
|
return UploadTaobaoPost(url, refere, isUtf8, data, false, cookies);
|
|
}
|
|
public static string UploadTaobaoPost(string url, string refere, bool isUtf8, string data, string cookies)
|
|
{
|
|
return UploadTaobaoPost(url, refere, isUtf8, data, false, cookies);
|
|
}
|
|
|
|
public static string UploadFxgPost(string url, string refere, bool isUtf8, string data, string cookies)
|
|
{
|
|
return UploadFxgPost(url, refere, isUtf8, data, true, cookies);
|
|
}
|
|
|
|
public static string UploadFilePost(string url, string refere, bool isUtf8, NameValueCollection stringDict, string cookies)
|
|
{
|
|
bool againt = false;
|
|
try
|
|
{
|
|
cookies = GetCookies(url, cookies);
|
|
if (string.IsNullOrEmpty(cookies))
|
|
cookies = BaseClass.ChromeCookies;
|
|
string pdd = "";
|
|
if (!string.IsNullOrEmpty(cookies))
|
|
pdd = BaseRegex.GetMatchRegexString(ref cookies, "PDDAccessToken=([^;]+?);");
|
|
Againt:
|
|
string userAgent = BaseClass.ChromeUserAgent;
|
|
var boundary = "----------QkZCM0JGQjYtQzkwRC1CRkU0LUFFQjctMUEyM0M5MkVDMTMz";
|
|
// 边界符
|
|
var beginBoundary = Encoding.ASCII.GetBytes("--" + boundary + "\r\n");
|
|
//var fileStream = new FileStream(filePath, FileMode.Open, FileAccess.Read);
|
|
// 最后的结束符
|
|
var endBoundary = Encoding.ASCII.GetBytes("--" + boundary + "--\r\n");
|
|
WebClientx wb = new WebClientx();
|
|
wb.Timeout = 30;
|
|
wb.AllowAutoRedirect = true;
|
|
wb.Headers.Add("Accept", "application/json, text/javascript, */*; q=0.01");
|
|
wb.Headers.Add("X-Requested-With", "XMLHttpRequest");
|
|
wb.Headers.Add("Accept-Encoding", "gzip,deflate");
|
|
if(url.Contains("https://s.taobao.com/image"))
|
|
wb.Headers.Add("Origin", "https://www.taobao.com");
|
|
if (!string.IsNullOrEmpty(cookies) && cookies.Contains("PDDAccessToken") && BaseClass.CookiesAll.ContainsKey("yangkeduo.com") && BaseClass.CookiesAll["yangkeduo.com"].ContainsKey("PDDAccessToken"))
|
|
wb.Headers.Add("accesstoken", BaseClass.CookiesAll["yangkeduo.com"]["PDDAccessToken"]);
|
|
else if (!string.IsNullOrEmpty(pdd))
|
|
wb.Headers.Add("accesstoken", pdd);
|
|
wb.Headers.Add("Accept-Language", "zh-cn,zh;q=0.8,en-us;q=0.5,en;q=0.3");
|
|
wb.Headers.Add("User-Agent", userAgent);
|
|
wb.Proxy = null;
|
|
if (!string.IsNullOrEmpty(refere))
|
|
wb.Headers.Add("Referer", refere);
|
|
if (!string.IsNullOrEmpty(cookies))
|
|
wb.Headers.Add("Cookie", cookies);
|
|
wb.Proxy = null;
|
|
string rehead = wb.Headers.ToString();
|
|
var encode = isUtf8 ? Encoding.UTF8 : Encoding.GetEncoding("gbk");
|
|
byte[] b;
|
|
string html, head;
|
|
try
|
|
{
|
|
var memStream = new MemoryStream();
|
|
wb.Headers.Add("Content-Type", "multipart/form-data; boundary=" + boundary);
|
|
memStream.Write(beginBoundary, 0, beginBoundary.Length);
|
|
// 写入字符串的Key
|
|
var stringKeyHeader = "\r\n--" + boundary +
|
|
"\r\nContent-Disposition: form-data; name=\"{0}\"" +
|
|
"\r\n\r\n{1}\r\n";
|
|
|
|
foreach (byte[] formitembytes in from string key in stringDict.Keys
|
|
select string.Format(stringKeyHeader, key, stringDict[key])
|
|
into formitem
|
|
select Encoding.UTF8.GetBytes(formitem))
|
|
{
|
|
memStream.Write(formitembytes, 0, formitembytes.Length);
|
|
}
|
|
|
|
// 写入最后的结束边界符
|
|
memStream.Write(endBoundary, 0, endBoundary.Length);
|
|
wb.Headers.Add("ContentLength", memStream.Length.ToString());
|
|
var tempBuffer = memStream.ToArray();
|
|
b = wb.UploadData(url, "POST", tempBuffer);
|
|
html = encode.GetString(b);
|
|
|
|
string c = BaseRegex.GetMatchRegexString(wb.ResponseHeaders["Content-Type"], "charset\\s*=\\s*(\\S+)");
|
|
if (!string.IsNullOrEmpty(c))
|
|
{
|
|
c = c.Trim().ToLower().Replace("utf8", "utf-8");
|
|
}
|
|
if (string.IsNullOrEmpty(c))
|
|
c = BaseRegex.GetMatchRegexString(html, @"<meta [^>]*?charset=[""']*([\w-]+)[""']*");
|
|
if (!string.IsNullOrEmpty(c))
|
|
{
|
|
if (c.IndexOf("'") > -1)
|
|
c = c.Substring(0, c.IndexOf("'"));
|
|
if (c.IndexOf("\"") > -1)
|
|
c = c.Substring(0, c.IndexOf("\""));
|
|
if (c.IndexOf(" ") > -1)
|
|
c = c.Substring(0, c.IndexOf(" "));
|
|
if (c.IndexOf(">") > -1)
|
|
c = c.Substring(0, c.IndexOf(">"));
|
|
if (!string.IsNullOrEmpty(c))
|
|
html = Encoding.GetEncoding(c).GetString(b);
|
|
}
|
|
head = wb.ResponseHeaders.ToString();
|
|
}
|
|
catch (Exception ee)
|
|
{
|
|
html = "提交错误:" + ee.Message;
|
|
head = "";
|
|
if (!againt)
|
|
{
|
|
againt = true;
|
|
Thread.Sleep(10 * 1000);
|
|
goto Againt;
|
|
}
|
|
}
|
|
return GetHtml.Decode(html);
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
LogSave.Add("访问网址错误:" + url + " " + e.Message);
|
|
return "";
|
|
}
|
|
}
|
|
|
|
public static string GetUrl(string url, string refere, bool isUtf8, string data, string sCookies = "")
|
|
{
|
|
try
|
|
{
|
|
string domain = GetHtml.GetDomain(url);
|
|
string mainDomain = GetHtml.GetMainDomain(domain);
|
|
string cookies = sCookies;
|
|
if (BaseClass.CookiesAllString.ContainsKey(mainDomain))
|
|
cookies = BaseClass.CookiesAllString[mainDomain];
|
|
else if (BaseClass.CookiesAllString.ContainsKey(domain))
|
|
cookies = BaseClass.CookiesAllString[domain];
|
|
string userAgent = BaseClass.ChromeUserAgent;
|
|
WebClientx wb = new WebClientx();
|
|
wb.Timeout = 30;
|
|
wb.AllowAutoRedirect = true;
|
|
wb.Headers.Add("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8");
|
|
//wb.Headers.Add("X-Requested-With", "XMLHttpRequest");
|
|
wb.Headers.Add("Accept-Encoding", "gzip,deflate");
|
|
wb.Headers.Add("Accept-Language", "zh-cn,zh;q=0.8,en-us;q=0.5,en;q=0.3");
|
|
wb.Headers.Add("User-Agent", userAgent);
|
|
wb.Proxy = null;
|
|
if (!string.IsNullOrEmpty(refere))
|
|
wb.Headers.Add("Referer", refere);
|
|
if (!string.IsNullOrEmpty(cookies))
|
|
wb.Headers.Add("Cookie", cookies);
|
|
wb.Proxy = null;
|
|
string rehead = wb.Headers.ToString();
|
|
var encode = isUtf8 ? Encoding.UTF8 : Encoding.GetEncoding("gbk");
|
|
byte[] b, postData = data == null ? new byte[0] : encode.GetBytes(data);
|
|
string html, head;
|
|
try
|
|
{
|
|
if (string.IsNullOrEmpty(data))
|
|
{
|
|
b = wb.DownloadData(url);
|
|
}
|
|
else
|
|
{
|
|
wb.Headers.Add("Content-Type", "application/x-www-form-urlencoded");
|
|
wb.Headers.Add("ContentLength", postData.Length.ToString());
|
|
b = wb.UploadData(url, "POST", postData);
|
|
}
|
|
html = encode.GetString(b);
|
|
|
|
string c = BaseRegex.GetMatchRegexString(wb.ResponseHeaders["Content-Type"], "charset\\s*=\\s*(\\S+)");
|
|
if (!string.IsNullOrEmpty(c))
|
|
{
|
|
c = c.Trim().ToLower().Replace("utf8", "utf-8");
|
|
}
|
|
if (string.IsNullOrEmpty(c))
|
|
c = BaseRegex.GetMatchRegexString(html, @"<meta [^>]*?charset=[""']*([\w-]+)[""']*");
|
|
if (!string.IsNullOrEmpty(c))
|
|
{
|
|
if (c.IndexOf("'") > -1)
|
|
c = c.Substring(0, c.IndexOf("'"));
|
|
if (c.IndexOf("\"") > -1)
|
|
c = c.Substring(0, c.IndexOf("\""));
|
|
if (c.IndexOf(" ") > -1)
|
|
c = c.Substring(0, c.IndexOf(" "));
|
|
if (c.IndexOf(">") > -1)
|
|
c = c.Substring(0, c.IndexOf(">"));
|
|
if (!string.IsNullOrEmpty(c))
|
|
html = Encoding.GetEncoding(c).GetString(b);
|
|
}
|
|
head = wb.ResponseHeaders.ToString();
|
|
}
|
|
catch (Exception ee)
|
|
{
|
|
html = "提交错误:" + ee.Message;
|
|
head = "";
|
|
}
|
|
return GetHtml.Decode(html);
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
LogSave.Add("访问网址错误:" + url + " " + e.Message);
|
|
return "";
|
|
}
|
|
}
|
|
|
|
public static string PostTaobaoNew(string url, string refere, bool isUtf8, string data)
|
|
{
|
|
bool againt = false;
|
|
try
|
|
{
|
|
string cookies = GetCookies(url, "");
|
|
if (string.IsNullOrEmpty(cookies))
|
|
cookies = BaseClass.ChromeCookies;
|
|
Againt:
|
|
string userAgent = BaseClass.ChromeUserAgent;
|
|
WebClientx wb = new WebClientx();
|
|
wb.Timeout = 30;
|
|
wb.AllowAutoRedirect = true;
|
|
wb.Headers.Add("Accept-Encoding", "gzip,deflate");
|
|
if (url.Contains("gy.taobao.com"))
|
|
wb.Headers.Add("Origin", "https://gy.taobao.com");
|
|
wb.Headers.Add("Accept-Language", "zh-cn,zh;q=0.8,en-us;q=0.5,en;q=0.3");
|
|
wb.Headers.Add("User-Agent", userAgent);
|
|
wb.Proxy = null;
|
|
if (!string.IsNullOrEmpty(refere))
|
|
wb.Headers.Add("Referer", refere);
|
|
if (!string.IsNullOrEmpty(cookies))
|
|
wb.Headers.Add("Cookie", cookies);
|
|
string rehead = wb.Headers.ToString();
|
|
var encode = isUtf8 ? Encoding.UTF8 : Encoding.GetEncoding("gbk");
|
|
byte[] b, postData = encode.GetBytes(data);
|
|
string html, head;
|
|
try
|
|
{
|
|
if (string.IsNullOrEmpty(data))
|
|
{
|
|
b = wb.DownloadData(url);
|
|
}
|
|
else
|
|
{
|
|
wb.Headers.Add("Content-Type", "application/x-www-form-urlencoded");
|
|
wb.Headers.Add("ContentLength", postData.Length.ToString());
|
|
b = wb.UploadData(url, "POST", postData);
|
|
}
|
|
html = encode.GetString(b);
|
|
|
|
string c = BaseRegex.GetMatchRegexString(wb.ResponseHeaders["Content-Type"], "charset\\s*=\\s*(\\S+)");
|
|
if (!string.IsNullOrEmpty(c))
|
|
{
|
|
c = c.Trim().ToLower().Replace("utf8", "utf-8");
|
|
}
|
|
if (string.IsNullOrEmpty(c))
|
|
c = BaseRegex.GetMatchRegexString(html, @"<meta [^>]*?charset=[""']*([\w-]+)[""']*");
|
|
if (!string.IsNullOrEmpty(c))
|
|
{
|
|
if (c.IndexOf("'") > -1)
|
|
c = c.Substring(0, c.IndexOf("'"));
|
|
if (c.IndexOf("\"") > -1)
|
|
c = c.Substring(0, c.IndexOf("\""));
|
|
if (c.IndexOf(" ") > -1)
|
|
c = c.Substring(0, c.IndexOf(" "));
|
|
if (c.IndexOf(">") > -1)
|
|
c = c.Substring(0, c.IndexOf(">"));
|
|
if (!string.IsNullOrEmpty(c))
|
|
html = Encoding.GetEncoding(c).GetString(b);
|
|
}
|
|
head = wb.ResponseHeaders.ToString();
|
|
}
|
|
catch (Exception ee)
|
|
{
|
|
html = "提交错误:" + ee.Message;
|
|
head = "";
|
|
if (!againt)
|
|
{
|
|
againt = true;
|
|
Thread.Sleep(10 * 1000);
|
|
goto Againt;
|
|
}
|
|
}
|
|
return GetHtml.Decode(html);
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
LogSave.Add("访问网址错误:" + url + " " + e.Message);
|
|
return "";
|
|
}
|
|
}
|
|
|
|
public static string JsonPinduoduoUpload(string url, string refere, bool isUtf8, string data, string cookies)
|
|
{
|
|
cookies = GetCookies(url, cookies);
|
|
if (string.IsNullOrEmpty(cookies))
|
|
cookies = BaseClass.ChromeCookies;
|
|
string pdd = "";
|
|
if (!string.IsNullOrEmpty(cookies))
|
|
pdd = BaseRegex.GetMatchRegexString(ref cookies, "PDDAccessToken=([^;]+?);");
|
|
string pddx = "";
|
|
if (!string.IsNullOrEmpty(cookies))
|
|
pddx = BaseRegex.GetMatchRegexString(ref cookies, "PASS_ID=([^;]+?);");
|
|
string userAgent = BaseClass.ChromeUserAgent;
|
|
WebClientx wb = new WebClientx();
|
|
wb.Timeout = 30;
|
|
wb.AllowAutoRedirect = true;
|
|
wb.Headers.Add("Accept", "application/json, text/javascript, */*; q=0.01");
|
|
wb.Headers.Add("Accept-Encoding", "gzip,deflate");
|
|
if (!string.IsNullOrEmpty(cookies) && cookies.Contains("PDDAccessToken") && BaseClass.CookiesAll.ContainsKey("yangkeduo.com") && BaseClass.CookiesAll["yangkeduo.com"].ContainsKey("PDDAccessToken"))
|
|
wb.Headers.Add("accesstoken", BaseClass.CookiesAll["yangkeduo.com"]["PDDAccessToken"]);
|
|
else if (!string.IsNullOrEmpty(pdd))
|
|
wb.Headers.Add("accesstoken", pdd);
|
|
else if (!string.IsNullOrEmpty(pddx))
|
|
wb.Headers.Add("PASSID", pddx);
|
|
if (url.Contains("mms.pinduoduo.com"))
|
|
wb.Headers.Add("Origin", "https://mms.pinduoduo.com");
|
|
wb.Headers.Add("Accept-Language", "zh-cn,zh;q=0.8,en-us;q=0.5,en;q=0.3");
|
|
wb.Headers.Add("User-Agent", userAgent);
|
|
wb.Proxy = null;
|
|
if (!string.IsNullOrEmpty(refere))
|
|
wb.Headers.Add("Referer", refere);
|
|
if (!string.IsNullOrEmpty(cookies))
|
|
wb.Headers.Add("Cookie", cookies);
|
|
wb.Proxy = null;
|
|
wb.Headers.Add("Content-Type", "application/json; charset=" + (isUtf8 ? "UTF-8" : "gbk"));
|
|
string rehead = wb.Headers.ToString();
|
|
var encode = isUtf8 ? Encoding.UTF8 : Encoding.GetEncoding("gbk");
|
|
byte[] b, postData = encode.GetBytes(data);
|
|
string html, head;
|
|
try
|
|
{
|
|
if (string.IsNullOrEmpty(data))
|
|
{
|
|
b = wb.DownloadData(url);
|
|
}
|
|
else
|
|
{
|
|
|
|
wb.Headers.Add("ContentLength", postData.Length.ToString());
|
|
b = wb.UploadData(url, "POST", postData);
|
|
}
|
|
html = encode.GetString(b);
|
|
return html;
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
LogSave.Add("访问网址错误:" + url + " " + e.Message);
|
|
return "";
|
|
}
|
|
}
|
|
|
|
public static string UploadTaobaoDetailPic(string url, string refere, bool isUtf8)
|
|
{
|
|
return UploadTaobaoPostDetail(url, refere, isUtf8, "", false, "");
|
|
}
|
|
public static string UploadTaobaoDetailPic(string url, string refere, bool isUtf8, string cookies)
|
|
{
|
|
return UploadTaobaoPostDetail(url, refere, isUtf8, "", false, cookies);
|
|
}
|
|
public static string UploadTaobaoPostDetail(string url, string refere, bool isUtf8, string data, bool isPost,
|
|
string cookies)
|
|
{
|
|
bool againt = false;
|
|
try
|
|
{
|
|
Againt:
|
|
string userAgent = BaseClass.ChromeUserAgent;
|
|
WebClientx wb = new WebClientx();
|
|
wb.Timeout = 30;
|
|
wb.AllowAutoRedirect = true;
|
|
wb.Headers.Add("Accept", "application/json, text/javascript, */*; q=0.01");
|
|
wb.Headers.Add("X-Requested-With", "XMLHttpRequest");
|
|
wb.Headers.Add("Accept-Encoding", "gzip,deflate");
|
|
if (!string.IsNullOrEmpty(cookies) && cookies.Contains("PDDAccessToken") && BaseClass.CookiesAll.ContainsKey("yangkeduo.com") && BaseClass.CookiesAll["yangkeduo.com"].ContainsKey("PDDAccessToken"))
|
|
wb.Headers.Add("accesstoken", BaseClass.CookiesAll["yangkeduo.com"]["PDDAccessToken"]);
|
|
if (url.Contains("gy.taobao.com"))
|
|
wb.Headers.Add("Origin", "https://gy.taobao.com");
|
|
if (url.Contains("mms.pinduoduo.com"))
|
|
wb.Headers.Add("Origin", "http://mms.pinduoduo.com");
|
|
//if (url.Contains("fuwu.pinduoduo.com"))
|
|
// wb.Headers.Add("Origin", "https://fuwu.pinduoduo.com");
|
|
wb.Headers.Add("Accept-Language", "zh-cn,zh;q=0.8,en-us;q=0.5,en;q=0.3");
|
|
wb.Headers.Add("User-Agent", userAgent);
|
|
wb.Proxy = null;
|
|
if (!string.IsNullOrEmpty(refere))
|
|
wb.Headers.Add("Referer", refere);
|
|
if (!string.IsNullOrEmpty(cookies))
|
|
wb.Headers.Add("Cookie", cookies);
|
|
string rehead = wb.Headers.ToString();
|
|
var encode = isUtf8 ? Encoding.UTF8 : Encoding.GetEncoding("gbk");
|
|
byte[] b, postData = encode.GetBytes(data);
|
|
string html, head;
|
|
try
|
|
{
|
|
if (string.IsNullOrEmpty(data) && !isPost)
|
|
{
|
|
b = wb.DownloadData(url);
|
|
}
|
|
else
|
|
{
|
|
if (isPost || url.Contains("taobao.com") || url.Contains("1688.com"))
|
|
{
|
|
wb.Headers.Add("Content-Type", "application/x-www-form-urlencoded");
|
|
}
|
|
else
|
|
{
|
|
wb.Headers.Add("Content-Type", "application/json; charset=" + (isUtf8 ? "UTF-8" : "gbk"));
|
|
}
|
|
wb.Headers.Add("ContentLength", postData.Length.ToString());
|
|
b = wb.UploadData(url, "POST", postData);
|
|
}
|
|
html = encode.GetString(b);
|
|
|
|
string c = BaseRegex.GetMatchRegexString(wb.ResponseHeaders["Content-Type"], "charset\\s*=\\s*(\\S+)");
|
|
if (!string.IsNullOrEmpty(c))
|
|
{
|
|
c = c.Trim().ToLower().Replace("utf8", "utf-8");
|
|
}
|
|
if (string.IsNullOrEmpty(c))
|
|
c = BaseRegex.GetMatchRegexString(html, @"<meta [^>]*?charset=[""']*([\w-]+)[""']*");
|
|
if (!string.IsNullOrEmpty(c))
|
|
{
|
|
if (c.IndexOf("'") > -1)
|
|
c = c.Substring(0, c.IndexOf("'"));
|
|
if (c.IndexOf("\"") > -1)
|
|
c = c.Substring(0, c.IndexOf("\""));
|
|
if (c.IndexOf(" ") > -1)
|
|
c = c.Substring(0, c.IndexOf(" "));
|
|
if (c.IndexOf(">") > -1)
|
|
c = c.Substring(0, c.IndexOf(">"));
|
|
if (!string.IsNullOrEmpty(c))
|
|
html = Encoding.GetEncoding(c).GetString(b);
|
|
}
|
|
head = wb.ResponseHeaders.ToString();
|
|
//string lo= response.Headers["Location"];
|
|
}
|
|
catch (Exception ee)
|
|
{
|
|
html = "提交错误:" + ee.Message;
|
|
head = "";
|
|
if (!againt)
|
|
{
|
|
againt = true;
|
|
Thread.Sleep(10 * 1000);
|
|
goto Againt;
|
|
}
|
|
}
|
|
return GetHtml.Decode(html);
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
LogSave.Add("访问网址错误:" + url + " " + e.Message);
|
|
return "";
|
|
}
|
|
}
|
|
public static string UploadTaobaoPost(string url, string refere, bool isUtf8, string data, bool isPost,
|
|
string cookies, int timeOut = 30)
|
|
{
|
|
bool againt = false;
|
|
try
|
|
{
|
|
cookies = GetCookies(url, cookies);
|
|
if (string.IsNullOrEmpty(cookies))
|
|
cookies = BaseClass.ChromeCookies;
|
|
string pdd = "";
|
|
if (!string.IsNullOrEmpty(cookies))
|
|
pdd = BaseRegex.GetMatchRegexString(ref cookies, "PDDAccessToken=([^;]+?);");
|
|
string pddx = "";
|
|
if (!string.IsNullOrEmpty(cookies))
|
|
pddx = BaseRegex.GetMatchRegexString(ref cookies, "[^_]PASS_ID=([^;]+?);");
|
|
Againt:
|
|
string userAgent = BaseClass.ChromeUserAgent;
|
|
WebClientx wb = new WebClientx();
|
|
wb.Timeout = timeOut;
|
|
wb.AllowAutoRedirect = true;
|
|
wb.Headers.Add("Accept", "application/json, text/javascript, */*; q=0.01");
|
|
wb.Headers.Add("X-Requested-With", "XMLHttpRequest");
|
|
wb.Headers.Add("Accept-Encoding", "gzip,deflate");
|
|
if (!string.IsNullOrEmpty(cookies) && cookies.Contains("PDDAccessToken") && BaseClass.CookiesAll.ContainsKey("yangkeduo.com") && BaseClass.CookiesAll["yangkeduo.com"].ContainsKey("PDDAccessToken"))
|
|
wb.Headers.Add("accesstoken", BaseClass.CookiesAll["yangkeduo.com"]["PDDAccessToken"]);
|
|
else if (!string.IsNullOrEmpty(pdd))
|
|
wb.Headers.Add("accesstoken", pdd);
|
|
else if (!string.IsNullOrEmpty(pddx))
|
|
wb.Headers.Add("PASSID", pddx);
|
|
if (url.Contains("gy.taobao.com"))
|
|
wb.Headers.Add("Origin", "https://gy.taobao.com");
|
|
if (url.Contains("mms.pinduoduo.com"))
|
|
wb.Headers.Add("Origin", "http://mms.pinduoduo.com");
|
|
//if (url.Contains("fuwu.pinduoduo.com"))
|
|
// wb.Headers.Add("Origin", "https://fuwu.pinduoduo.com");
|
|
wb.Headers.Add("Accept-Language", "zh-cn,zh;q=0.8,en-us;q=0.5,en;q=0.3");
|
|
wb.Headers.Add("User-Agent", userAgent);
|
|
wb.Proxy = null;
|
|
if (!string.IsNullOrEmpty(refere))
|
|
wb.Headers.Add("Referer", refere);
|
|
if (!string.IsNullOrEmpty(cookies))
|
|
wb.Headers.Add("Cookie", cookies);
|
|
string rehead = wb.Headers.ToString();
|
|
var encode = isUtf8 ? Encoding.UTF8 : Encoding.GetEncoding("gbk");
|
|
byte[] b, postData = encode.GetBytes(data);
|
|
string html, head;
|
|
try
|
|
{
|
|
if (string.IsNullOrEmpty(data) && !isPost)
|
|
{
|
|
b = wb.DownloadData(url);
|
|
}
|
|
else
|
|
{
|
|
if (isPost || url.Contains("taobao.com") || url.Contains("1688.com"))
|
|
{
|
|
wb.Headers.Add("Content-Type", "application/x-www-form-urlencoded");
|
|
}
|
|
else
|
|
{
|
|
wb.Headers.Add("Content-Type", "application/json; charset=" + (isUtf8 ? "UTF-8" : "gbk"));
|
|
}
|
|
wb.Headers.Add("ContentLength", postData.Length.ToString());
|
|
b = wb.UploadData(url, "POST", postData);
|
|
}
|
|
html = encode.GetString(b);
|
|
|
|
string c = BaseRegex.GetMatchRegexString(wb.ResponseHeaders["Content-Type"], "charset\\s*=\\s*(\\S+)");
|
|
if (!string.IsNullOrEmpty(c))
|
|
{
|
|
c = c.Trim().ToLower().Replace("utf8", "utf-8");
|
|
}
|
|
if (string.IsNullOrEmpty(c))
|
|
c = BaseRegex.GetMatchRegexString(html, @"<meta [^>]*?charset=[""']*([\w-]+)[""']*");
|
|
if (!string.IsNullOrEmpty(c))
|
|
{
|
|
if (c.IndexOf("'") > -1)
|
|
c = c.Substring(0, c.IndexOf("'"));
|
|
if (c.IndexOf("\"") > -1)
|
|
c = c.Substring(0, c.IndexOf("\""));
|
|
if (c.IndexOf(" ") > -1)
|
|
c = c.Substring(0, c.IndexOf(" "));
|
|
if (c.IndexOf(">") > -1)
|
|
c = c.Substring(0, c.IndexOf(">"));
|
|
if (!string.IsNullOrEmpty(c))
|
|
html = Encoding.GetEncoding(c).GetString(b);
|
|
}
|
|
head = wb.ResponseHeaders.ToString();
|
|
}
|
|
catch (Exception ee)
|
|
{
|
|
html = "提交错误:" + ee.Message;
|
|
head = "";
|
|
if (!againt)
|
|
{
|
|
againt = true;
|
|
Thread.Sleep(10 * 1000);
|
|
goto Againt;
|
|
}
|
|
}
|
|
return GetHtml.Decode(html);
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
LogSave.Add("访问网址错误:" + url + " " + e.Message);
|
|
return "";
|
|
}
|
|
|
|
}
|
|
|
|
public static string UploadFxgPost(string url, string refere, bool isUtf8, string data, bool isPost,
|
|
string cookies)
|
|
{
|
|
bool againt = false;
|
|
try
|
|
{
|
|
cookies = GetCookies(url, cookies);
|
|
if (string.IsNullOrEmpty(cookies))
|
|
cookies = BaseClass.ChromeCookies;
|
|
Againt:
|
|
string userAgent = BaseClass.ChromeUserAgent;
|
|
if (string.IsNullOrEmpty(userAgent))
|
|
{
|
|
userAgent = "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.198 Safari/537.36";
|
|
}
|
|
WebClientx wb = new WebClientx();
|
|
wb.Timeout = 30;
|
|
wb.AllowAutoRedirect = true;
|
|
wb.Headers.Add("Accept", "application/json, text/javascript, */*; q=0.01");
|
|
wb.Headers.Add("X-Requested-With", "XMLHttpRequest");
|
|
wb.Headers.Add("Accept-Encoding", "gzip,deflate");
|
|
wb.Headers.Add("Origin", "https://fxg.jinritemai.com");
|
|
wb.Headers.Add("Accept-Language", "zh-cn,zh;q=0.8,en-us;q=0.5,en;q=0.3");
|
|
wb.Headers.Add("Sec-Fetch-Site", "same-origin");
|
|
wb.Headers.Add("Sec-Fetch-Mode", "cors");
|
|
wb.Headers.Add("Sec-Fetch-Dest", "empty");
|
|
wb.Headers.Add("User-Agent", userAgent);
|
|
wb.Proxy = null;
|
|
if (!string.IsNullOrEmpty(refere))
|
|
wb.Headers.Add("Referer", refere);
|
|
if (!string.IsNullOrEmpty(cookies))
|
|
wb.Headers.Add("Cookie", cookies);
|
|
string rehead = wb.Headers.ToString();
|
|
var encode = isUtf8 ? Encoding.UTF8 : Encoding.GetEncoding("gbk");
|
|
byte[] b, postData = encode.GetBytes(data);
|
|
string html, head;
|
|
try
|
|
{
|
|
if (string.IsNullOrEmpty(data) && !isPost)
|
|
{
|
|
b = wb.DownloadData(url);
|
|
}
|
|
else
|
|
{
|
|
if (isPost)
|
|
{
|
|
wb.Headers.Add("Content-Type", "application/x-www-form-urlencoded");
|
|
//}
|
|
//else
|
|
//{
|
|
//wb.Headers.Add("Content-Type", "application/json; charset=" + (isUtf8 ? "UTF-8" : "gbk"));
|
|
}
|
|
wb.Headers.Add("ContentLength", postData.Length.ToString());
|
|
b = wb.UploadData(url, "POST", postData);
|
|
}
|
|
html = encode.GetString(b);
|
|
|
|
string c = BaseRegex.GetMatchRegexString(wb.ResponseHeaders["Content-Type"], "charset\\s*=\\s*(\\S+)");
|
|
if (!string.IsNullOrEmpty(c))
|
|
{
|
|
c = c.Trim().ToLower().Replace("utf8", "utf-8");
|
|
}
|
|
if (string.IsNullOrEmpty(c))
|
|
c = BaseRegex.GetMatchRegexString(html, @"<meta [^>]*?charset=[""']*([\w-]+)[""']*");
|
|
if (!string.IsNullOrEmpty(c))
|
|
{
|
|
if (c.IndexOf("'") > -1)
|
|
c = c.Substring(0, c.IndexOf("'"));
|
|
if (c.IndexOf("\"") > -1)
|
|
c = c.Substring(0, c.IndexOf("\""));
|
|
if (c.IndexOf(" ") > -1)
|
|
c = c.Substring(0, c.IndexOf(" "));
|
|
if (c.IndexOf(">") > -1)
|
|
c = c.Substring(0, c.IndexOf(">"));
|
|
if (!string.IsNullOrEmpty(c))
|
|
html = Encoding.GetEncoding(c).GetString(b);
|
|
}
|
|
head = wb.ResponseHeaders.ToString();
|
|
}
|
|
catch (Exception ee)
|
|
{
|
|
html = "提交错误:" + ee.Message;
|
|
head = "";
|
|
if (!againt)
|
|
{
|
|
againt = true;
|
|
Thread.Sleep(10 * 1000);
|
|
goto Againt;
|
|
}
|
|
}
|
|
return GetHtml.Decode(html);
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
LogSave.Add("访问网址错误:" + url + " " + e.Message);
|
|
return "";
|
|
}
|
|
|
|
}
|
|
|
|
public static string UploadTaobaoPost(string url, string refere, bool isUtf8, string data, string cookies,string codex)
|
|
{
|
|
return UploadTaobaoPost(url, refere, isUtf8, data, false, cookies,codex);
|
|
}
|
|
public static string UploadTaobaoPost(string url, string refere, bool isUtf8, string data, bool isPost,
|
|
string cookies,string codex)
|
|
{
|
|
bool againt = false;
|
|
try
|
|
{
|
|
cookies = GetCookies(url, cookies);
|
|
if (string.IsNullOrEmpty(cookies))
|
|
cookies = BaseClass.ChromeCookies;
|
|
string pdd = "";
|
|
if (!string.IsNullOrEmpty(cookies))
|
|
pdd = BaseRegex.GetMatchRegexString(ref cookies, "PDDAccessToken=([^;]+?);");
|
|
string pddx = "";
|
|
if (!string.IsNullOrEmpty(cookies))
|
|
pddx = BaseRegex.GetMatchRegexString(ref cookies, "[^_]PASS_ID=([^;]+?);");
|
|
Againt:
|
|
string userAgent = BaseClass.ChromeUserAgent;
|
|
WebClientx wb = new WebClientx();
|
|
wb.Timeout = 30;
|
|
wb.AllowAutoRedirect = true;
|
|
wb.Headers.Add("Accept", "application/json, text/javascript, */*; q=0.01");
|
|
wb.Headers.Add("X-Requested-With", "XMLHttpRequest");
|
|
wb.Headers.Add("Accept-Encoding", "gzip,deflate");
|
|
wb.Headers.Add("Anti-Content", codex);
|
|
if (!string.IsNullOrEmpty(cookies) && cookies.Contains("PDDAccessToken") && BaseClass.CookiesAll.ContainsKey("yangkeduo.com") && BaseClass.CookiesAll["yangkeduo.com"].ContainsKey("PDDAccessToken"))
|
|
wb.Headers.Add("accesstoken", BaseClass.CookiesAll["yangkeduo.com"]["PDDAccessToken"]);
|
|
else if (!string.IsNullOrEmpty(pdd))
|
|
wb.Headers.Add("accesstoken", pdd);
|
|
else if (!string.IsNullOrEmpty(pddx))
|
|
wb.Headers.Add("PASSID", pddx);
|
|
if (url.Contains("gy.taobao.com"))
|
|
wb.Headers.Add("Origin", "https://gy.taobao.com");
|
|
if (url.Contains("mms.pinduoduo.com"))
|
|
wb.Headers.Add("Origin", "http://mms.pinduoduo.com");
|
|
wb.Headers.Add("Accept-Language", "zh-cn,zh;q=0.8,en-us;q=0.5,en;q=0.3");
|
|
wb.Headers.Add("User-Agent", userAgent);
|
|
wb.Proxy = null;
|
|
if (!string.IsNullOrEmpty(refere))
|
|
wb.Headers.Add("Referer", refere);
|
|
if (!string.IsNullOrEmpty(cookies))
|
|
wb.Headers.Add("Cookie", cookies);
|
|
string rehead = wb.Headers.ToString();
|
|
var encode = isUtf8 ? Encoding.UTF8 : Encoding.GetEncoding("gbk");
|
|
byte[] b, postData = encode.GetBytes(data);
|
|
string html, head;
|
|
try
|
|
{
|
|
if (string.IsNullOrEmpty(data) && !isPost)
|
|
{
|
|
b = wb.DownloadData(url);
|
|
}
|
|
else
|
|
{
|
|
if (isPost || url.Contains("taobao.com") || url.Contains("1688.com"))
|
|
{
|
|
wb.Headers.Add("Content-Type", "application/x-www-form-urlencoded");
|
|
}
|
|
else
|
|
{
|
|
wb.Headers.Add("Content-Type", "application/json; charset=" + (isUtf8 ? "UTF-8" : "gbk"));
|
|
}
|
|
wb.Headers.Add("ContentLength", postData.Length.ToString());
|
|
b = wb.UploadData(url, "POST", postData);
|
|
}
|
|
html = encode.GetString(b);
|
|
|
|
string c = BaseRegex.GetMatchRegexString(wb.ResponseHeaders["Content-Type"], "charset\\s*=\\s*(\\S+)");
|
|
if (!string.IsNullOrEmpty(c))
|
|
{
|
|
c = c.Trim().ToLower().Replace("utf8", "utf-8");
|
|
}
|
|
if (string.IsNullOrEmpty(c))
|
|
c = BaseRegex.GetMatchRegexString(html, @"<meta [^>]*?charset=[""']*([\w-]+)[""']*");
|
|
if (!string.IsNullOrEmpty(c))
|
|
{
|
|
if (c.IndexOf("'") > -1)
|
|
c = c.Substring(0, c.IndexOf("'"));
|
|
if (c.IndexOf("\"") > -1)
|
|
c = c.Substring(0, c.IndexOf("\""));
|
|
if (c.IndexOf(" ") > -1)
|
|
c = c.Substring(0, c.IndexOf(" "));
|
|
if (c.IndexOf(">") > -1)
|
|
c = c.Substring(0, c.IndexOf(">"));
|
|
if (!string.IsNullOrEmpty(c))
|
|
html = Encoding.GetEncoding(c).GetString(b);
|
|
}
|
|
head = wb.ResponseHeaders.ToString();
|
|
}
|
|
catch (Exception ee)
|
|
{
|
|
html = "提交错误:" + ee.Message;
|
|
head = "";
|
|
if (!againt)
|
|
{
|
|
againt = true;
|
|
Thread.Sleep(10 * 1000);
|
|
goto Againt;
|
|
}
|
|
}
|
|
return GetHtml.Decode(html);
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
LogSave.Add("访问网址错误:" + url + " " + e.Message);
|
|
return "";
|
|
}
|
|
|
|
}
|
|
|
|
public static string UploadTaobaoPostWhite(string url, string refere, bool isUtf8, string data, string cookies, string codex ,string VerifyAuthToken)
|
|
{
|
|
return UploadTaobaoPostWhite(url, refere, isUtf8, data, false, cookies, codex, VerifyAuthToken);
|
|
}
|
|
public static string UploadTaobaoPostWhite(string url, string refere, bool isUtf8, string data, bool isPost,
|
|
string cookies, string codex,string VerifyAuthToken)
|
|
{
|
|
bool againt = false;
|
|
try
|
|
{
|
|
Againt:
|
|
string userAgent = BaseClass.ChromeUserAgent;
|
|
WebClientx wb = new WebClientx();
|
|
wb.Timeout = 30;
|
|
wb.AllowAutoRedirect = true;
|
|
wb.Headers.Add("Accept", "application/json, text/javascript, */*; q=0.01");
|
|
wb.Headers.Add("X-Requested-With", "XMLHttpRequest");
|
|
wb.Headers.Add("Accept-Encoding", "gzip,deflate");
|
|
wb.Headers.Add("Anti-Content", codex);
|
|
wb.Headers.Add("VerifyAuthToken", VerifyAuthToken);
|
|
wb.Headers.Add("Origin", "https://aid.pinduoduo.com");
|
|
wb.Headers.Add("Accept-Language", "zh-cn,zh;q=0.8,en-us;q=0.5,en;q=0.3");
|
|
wb.Headers.Add("User-Agent", userAgent);
|
|
wb.Proxy = null;
|
|
if (!string.IsNullOrEmpty(refere))
|
|
wb.Headers.Add("Referer", refere);
|
|
if (!string.IsNullOrEmpty(cookies))
|
|
wb.Headers.Add("Cookie", cookies);
|
|
string rehead = wb.Headers.ToString();
|
|
var encode = isUtf8 ? Encoding.UTF8 : Encoding.GetEncoding("gbk");
|
|
byte[] b, postData = encode.GetBytes(data);
|
|
string html, head;
|
|
try
|
|
{
|
|
if (string.IsNullOrEmpty(data) && !isPost)
|
|
{
|
|
b = wb.DownloadData(url);
|
|
}
|
|
else
|
|
{
|
|
if (isPost || url.Contains("taobao.com") || url.Contains("1688.com"))
|
|
{
|
|
wb.Headers.Add("Content-Type", "application/x-www-form-urlencoded");
|
|
}
|
|
else
|
|
{
|
|
wb.Headers.Add("Content-Type", "application/json; charset=" + (isUtf8 ? "UTF-8" : "gbk"));
|
|
}
|
|
wb.Headers.Add("ContentLength", postData.Length.ToString());
|
|
b = wb.UploadData(url, "POST", postData);
|
|
}
|
|
html = encode.GetString(b);
|
|
|
|
string c = BaseRegex.GetMatchRegexString(wb.ResponseHeaders["Content-Type"], "charset\\s*=\\s*(\\S+)");
|
|
if (!string.IsNullOrEmpty(c))
|
|
{
|
|
c = c.Trim().ToLower().Replace("utf8", "utf-8");
|
|
}
|
|
if (string.IsNullOrEmpty(c))
|
|
c = BaseRegex.GetMatchRegexString(html, @"<meta [^>]*?charset=[""']*([\w-]+)[""']*");
|
|
if (!string.IsNullOrEmpty(c))
|
|
{
|
|
if (c.IndexOf("'") > -1)
|
|
c = c.Substring(0, c.IndexOf("'"));
|
|
if (c.IndexOf("\"") > -1)
|
|
c = c.Substring(0, c.IndexOf("\""));
|
|
if (c.IndexOf(" ") > -1)
|
|
c = c.Substring(0, c.IndexOf(" "));
|
|
if (c.IndexOf(">") > -1)
|
|
c = c.Substring(0, c.IndexOf(">"));
|
|
if (!string.IsNullOrEmpty(c))
|
|
html = Encoding.GetEncoding(c).GetString(b);
|
|
}
|
|
head = wb.ResponseHeaders.ToString();
|
|
}
|
|
catch (Exception ee)
|
|
{
|
|
html = "提交错误:" + ee.Message;
|
|
head = "";
|
|
if (!againt)
|
|
{
|
|
againt = true;
|
|
Thread.Sleep(10 * 1000);
|
|
goto Againt;
|
|
}
|
|
}
|
|
return GetHtml.Decode(html);
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
LogSave.Add("访问网址错误:" + url + " " + e.Message);
|
|
return "";
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public static string UploadTransitTaobao(string url, string refere, bool isUtf8)
|
|
{
|
|
string cookies = GetCookies(url, "");
|
|
return UploadTransitTaobaoPost(url, refere, isUtf8, "", false, cookies);
|
|
}
|
|
|
|
public static string createtRansit()
|
|
{
|
|
// string pkey = @" -----BEGIN PUBLIC KEY----
|
|
//MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCJ50kaClQ5XTQfzkHAW9Ehi+iXQKUwVWg1R0SC3uYIlVmneu6AfVPEj6ovMmHa2ucq0qCUlMK+ACUPejzMZbcRAMtDAM+o0XYujcGxJpcc6jHhZGO0QSRK37+i47RbCxcdsUZUB5AS0BAIQOTfRW8XUrrGzmZWtiypu/97lKVpeQIDAQAB
|
|
//-----END PUBLIC KEY-----";
|
|
// string data = "sycmsycmsycmsycm";
|
|
// var rsa = new RSA(pkey, true);
|
|
// string transit_id = rsa.Encode(data);
|
|
string pkey = " -----BEGIN PUBLIC KEY----\nMIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCJ50kaClQ5XTQfzkHAW9Ehi+iXQKUwVWg1R0SC3uYIlVmneu6AfVPEj6ovMmHa2ucq0qCUlMK+ACUPejzMZbcRAMtDAM+o0XYujcGxJpcc6jHhZGO0QSRK37+i47RbCxcdsUZUB5AS0BAIQOTfRW8XUrrGzmZWtiypu/97lKVpeQIDAQAB\n-----END PUBLIC KEY-----";
|
|
string data = "w28Cz694s63kBYk4";
|
|
var rsa = new RSA(pkey, true);
|
|
string transit_id = rsa.Encode(data);
|
|
return transit_id;
|
|
}
|
|
public static string UploadTransitTaobaoPost(string url, string refere, bool isUtf8, string data, bool isPost,
|
|
string cookies)
|
|
{
|
|
bool againt = false;
|
|
try
|
|
{
|
|
cookies = GetCookies(url, cookies);
|
|
if (string.IsNullOrEmpty(cookies))
|
|
cookies = BaseClass.ChromeCookies;
|
|
string pdd = "";
|
|
if (!string.IsNullOrEmpty(cookies))
|
|
pdd = BaseRegex.GetMatchRegexString(ref cookies, "PDDAccessToken=([^;]+?);");
|
|
string pddx = "";
|
|
if (!string.IsNullOrEmpty(cookies))
|
|
pddx = BaseRegex.GetMatchRegexString(ref cookies, "PASS_ID=([^;]+?);");
|
|
Againt:
|
|
string userAgent = BaseClass.ChromeUserAgent;
|
|
WebClientx wb = new WebClientx();
|
|
wb.Timeout = 30;
|
|
wb.AllowAutoRedirect = true;
|
|
wb.Headers.Add("Accept", "application/json, text/javascript, */*; q=0.01");
|
|
wb.Headers.Add("X-Requested-With", "XMLHttpRequest");
|
|
wb.Headers.Add("Accept-Encoding", "gzip,deflate");
|
|
if (!string.IsNullOrEmpty(cookies) && cookies.Contains("PDDAccessToken") && BaseClass.CookiesAll.ContainsKey("yangkeduo.com") && BaseClass.CookiesAll["yangkeduo.com"].ContainsKey("PDDAccessToken"))
|
|
wb.Headers.Add("accesstoken", BaseClass.CookiesAll["yangkeduo.com"]["PDDAccessToken"]);
|
|
else if (!string.IsNullOrEmpty(pdd))
|
|
wb.Headers.Add("accesstoken", pdd);
|
|
else if (!string.IsNullOrEmpty(pddx))
|
|
wb.Headers.Add("PASSID", pddx);
|
|
if (url.Contains("gy.taobao.com"))
|
|
wb.Headers.Add("Origin", "https://gy.taobao.com");
|
|
if (url.Contains("mms.pinduoduo.com"))
|
|
wb.Headers.Add("Origin", "http://mms.pinduoduo.com");
|
|
wb.Headers.Add("Accept-Language", "zh-cn,zh;q=0.8,en-us;q=0.5,en;q=0.3");
|
|
wb.Headers.Add("User-Agent", userAgent);
|
|
wb.Headers.Add("transit-id", createtRansit());
|
|
wb.Proxy = null;
|
|
if (!string.IsNullOrEmpty(refere))
|
|
wb.Headers.Add("Referer", refere);
|
|
if (!string.IsNullOrEmpty(cookies))
|
|
wb.Headers.Add("Cookie", cookies);
|
|
string rehead = wb.Headers.ToString();
|
|
var encode = isUtf8 ? Encoding.UTF8 : Encoding.GetEncoding("gbk");
|
|
byte[] b, postData = encode.GetBytes(data);
|
|
string html, head;
|
|
try
|
|
{
|
|
if (string.IsNullOrEmpty(data) && !isPost)
|
|
{
|
|
b = wb.DownloadData(url);
|
|
}
|
|
else
|
|
{
|
|
if (isPost || url.Contains("taobao.com") || url.Contains("1688.com"))
|
|
{
|
|
wb.Headers.Add("Content-Type", "application/x-www-form-urlencoded");
|
|
}
|
|
else
|
|
{
|
|
wb.Headers.Add("Content-Type", "application/json; charset=" + (isUtf8 ? "UTF-8" : "gbk"));
|
|
}
|
|
wb.Headers.Add("ContentLength", postData.Length.ToString());
|
|
b = wb.UploadData(url, "POST", postData);
|
|
}
|
|
html = encode.GetString(b);
|
|
|
|
string c = BaseRegex.GetMatchRegexString(wb.ResponseHeaders["Content-Type"], "charset\\s*=\\s*(\\S+)");
|
|
if (!string.IsNullOrEmpty(c))
|
|
{
|
|
c = c.Trim().ToLower().Replace("utf8", "utf-8");
|
|
}
|
|
if (string.IsNullOrEmpty(c))
|
|
c = BaseRegex.GetMatchRegexString(html, @"<meta [^>]*?charset=[""']*([\w-]+)[""']*");
|
|
if (!string.IsNullOrEmpty(c))
|
|
{
|
|
if (c.IndexOf("'") > -1)
|
|
c = c.Substring(0, c.IndexOf("'"));
|
|
if (c.IndexOf("\"") > -1)
|
|
c = c.Substring(0, c.IndexOf("\""));
|
|
if (c.IndexOf(" ") > -1)
|
|
c = c.Substring(0, c.IndexOf(" "));
|
|
if (c.IndexOf(">") > -1)
|
|
c = c.Substring(0, c.IndexOf(">"));
|
|
if (!string.IsNullOrEmpty(c))
|
|
html = Encoding.GetEncoding(c).GetString(b);
|
|
}
|
|
head = wb.ResponseHeaders.ToString();
|
|
}
|
|
catch (Exception ee)
|
|
{
|
|
html = "提交错误:" + ee.Message;
|
|
head = "";
|
|
if (!againt)
|
|
{
|
|
againt = true;
|
|
Thread.Sleep(10 * 1000);
|
|
goto Againt;
|
|
}
|
|
}
|
|
return GetHtml.Decode(html);
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
LogSave.Add("访问网址错误:" + url + " " + e.Message);
|
|
return "";
|
|
}
|
|
|
|
}
|
|
/// <summary>
|
|
/// POST数据
|
|
/// </summary>
|
|
/// <param name="url">网址</param>
|
|
/// <param name="refere">来源</param>
|
|
/// <param name="isUtf8">编码是否为UTF-8</param>
|
|
/// <param name="data">数据</param>
|
|
/// <param name="isPost">是否强制为post提交</param>
|
|
/// <returns></returns>
|
|
public static string UploadTaobaoPost(string url, string refere, bool isUtf8, string data, bool isPost)
|
|
{
|
|
string cookies = GetCookies(url, "");
|
|
return UploadTaobaoPost(url, refere, isUtf8, data, isPost, cookies);
|
|
}
|
|
|
|
public static string GetJsonPost(string url, string refere, bool isUtf8, string data)
|
|
{
|
|
string cookies = string.IsNullOrEmpty(BaseClass.ChromeCookies) ? IECookies.GetCookieByWebBrowser(url) : BaseClass.ChromeCookies;
|
|
cookies = GetCookies(url, cookies);
|
|
return GetJsonPost(url, refere, isUtf8, data, cookies);
|
|
}
|
|
|
|
public static DateTime GetIpTime = new DateTime();
|
|
public static List<string> DailiIps = new List<string>();
|
|
public static string GetByProxy(string url, bool isUtf8)
|
|
{
|
|
if (GetIpTime < DateTime.Now.AddSeconds(-300) )
|
|
{
|
|
string urlx = "http://vip-custom.66daili.cn/proxypool/proxy/anxmvipvip/HJIHIUJIOP/66daili/";
|
|
//urlx = "http://pdd-custom.66daili.cn/proxypool/custom/2401348571901983939/66daili";
|
|
//if (Randomx.GetId(100) < 50)
|
|
// urlx = "http://pdd-custom.66daili.cn/proxypool/custom/2401400501901983956/66daili";
|
|
string html = GetHtml.Utf8(urlx);
|
|
if (!string.IsNullOrEmpty(html) && html.Contains(":"))
|
|
{
|
|
string[] l = html.Split('\n');
|
|
DailiIps.Clear();
|
|
for (int i = 0; i < l.Length; i++)
|
|
{
|
|
if(string.IsNullOrEmpty(l[i]) || !l[i].Contains(":"))
|
|
continue;
|
|
DailiIps.Add(l[i].Trim());
|
|
}
|
|
}
|
|
}
|
|
if (DailiIps.Count < 50)
|
|
return "";
|
|
string proxy = DailiIps[Randomx.GetId(DailiIps.Count)];
|
|
return GetJsonPost(url, url, isUtf8, "", "", proxy);
|
|
}
|
|
|
|
|
|
public static string GetJsonPostByProxy(string url, string refere, bool isUtf8, string data, string cookies)
|
|
{
|
|
string urlx = "http://vip-custom.66daili.cn/proxypool/proxy/anxmvipvip/HJIHIUJIOP/66daili/";
|
|
string html = GetHtml.Utf8(urlx);
|
|
string proxy = "";
|
|
if (!string.IsNullOrEmpty(html) && html.Contains(":"))
|
|
{
|
|
string[] l = html.Split('\n');
|
|
proxy = l[Randomx.GetId(l.Length)].Trim();
|
|
}
|
|
return GetJsonPost(url, refere, isUtf8, data, cookies, proxy);
|
|
}
|
|
|
|
/// <summary>
|
|
/// json提交数据
|
|
/// </summary>
|
|
/// <param name="url"></param>
|
|
/// <param name="refere"></param>
|
|
/// <param name="isUtf8"></param>
|
|
/// <param name="data"></param>
|
|
/// <returns></returns>
|
|
public static string GetJsonPost(string url, string refere, bool isUtf8, string data, string cookies, string proxy)
|
|
{
|
|
string userAgent = string.IsNullOrEmpty(BaseClass.ChromeUserAgent) ? BaseClass.UserAgent : BaseClass.ChromeUserAgent;
|
|
WebClientx wb = new WebClientx();
|
|
if (string.IsNullOrEmpty(cookies))
|
|
cookies = GetCookies(url, cookies);
|
|
wb.Timeout = 10;
|
|
|
|
wb.AllowAutoRedirect = false;
|
|
//wb.Timeout = 70;
|
|
//wb.Headers.Add("Accept", "application/json, text/javascript, */*; q=0.01");
|
|
wb.Headers.Add("Accept-Encoding", "gzip,deflate");
|
|
wb.Headers.Add("Accept-Language", "zh-cn,zh;q=0.8,en-us;q=0.5,en;q=0.3");
|
|
wb.Headers.Add("User-Agent", userAgent);
|
|
if (!string.IsNullOrEmpty(refere))
|
|
wb.Headers.Add("Referer", refere);
|
|
if (!string.IsNullOrEmpty(cookies))
|
|
wb.Headers.Add("Cookie", cookies);
|
|
if (!string.IsNullOrEmpty(proxy))
|
|
wb.Proxy = new WebProxy(proxy);
|
|
else
|
|
wb.Proxy = null;
|
|
string pdd = "";
|
|
if (!string.IsNullOrEmpty(cookies))
|
|
pdd = BaseRegex.GetMatchRegexString(ref cookies, "PDDAccessToken=([^;]+?);");
|
|
string pddx = "";
|
|
if (!string.IsNullOrEmpty(cookies))
|
|
pddx = BaseRegex.GetMatchRegexString(ref cookies, "PASS_ID=([^;]+)");
|
|
else if (!string.IsNullOrEmpty(pddx))
|
|
wb.Headers.Add("PASSID", pddx);
|
|
if (url.Contains("gy.taobao.com"))
|
|
wb.Headers.Add("Origin", "https://gy.taobao.com");
|
|
if (url.Contains("mms.pinduoduo.com"))
|
|
wb.Headers.Add("Origin", "https://mms.pinduoduo.com");
|
|
//wb.Proxy = null;
|
|
string rehead = wb.Headers.ToString();
|
|
var encode = isUtf8 ? Encoding.UTF8 : Encoding.GetEncoding("gbk");
|
|
byte[] b, postData = encode.GetBytes(data);
|
|
string html, head;
|
|
try
|
|
{
|
|
|
|
wb.Headers.Add("Accept", "application/json");
|
|
wb.Headers.Add("Content-Type", "application/json; charset=UTF-8");
|
|
if (string.IsNullOrEmpty(data))
|
|
{
|
|
b = wb.DownloadData(url);
|
|
}
|
|
else
|
|
{
|
|
//wb.Headers.Add("Content-Type", "application/x-www-form-urlencoded");
|
|
wb.Headers.Add("ContentLength", postData.Length.ToString());
|
|
rehead = wb.Headers.ToString();
|
|
b = wb.UploadData(url, "POST", postData);
|
|
}
|
|
html = encode.GetString(b);
|
|
head = wb.ResponseHeaders.ToString();
|
|
if (url.Contains("https://mms.pinduoduo.com/auth"))//拼多多登录专用
|
|
{
|
|
string domainUrl = "https://mms.pinduoduo.com";
|
|
string setCookies = wb.ResponseHeaders["Set-Cookie"];
|
|
string k = "PASS_ID";
|
|
string v = BaseRegex.GetMatchRegexString(setCookies, "PASS_ID=([^;]+?);");
|
|
var cookieManager = CefSharp.Cef.GetGlobalCookieManager();
|
|
var cookie = new CefSharp.Cookie
|
|
{
|
|
Name = k,
|
|
Value = v,
|
|
Expires = DateTime.Now.AddYears(1),
|
|
Path = "/",
|
|
HttpOnly = true
|
|
};
|
|
Task<bool> task = cookieManager.SetCookieAsync(domainUrl, cookie);
|
|
while (!task.IsCompleted)
|
|
{
|
|
Thread.Sleep(1);
|
|
}
|
|
BaseClass.ChromeCookies += " PASS_ID=" + v + ";";
|
|
}
|
|
}
|
|
catch (Exception ee)
|
|
{
|
|
html = "提交错误:" + ee.Message;
|
|
head = "";
|
|
}
|
|
return html;
|
|
}
|
|
|
|
/// <summary>
|
|
/// json提交数据
|
|
/// </summary>
|
|
/// <param name="url"></param>
|
|
/// <param name="refere"></param>
|
|
/// <param name="isUtf8"></param>
|
|
/// <param name="data"></param>
|
|
/// <returns></returns>
|
|
public static string GetJsonPost(string url, string refere, bool isUtf8, string data, string cookies)
|
|
{
|
|
string userAgent = string.IsNullOrEmpty(BaseClass.ChromeUserAgent) ? BaseClass.UserAgent : BaseClass.ChromeUserAgent;
|
|
WebClientx wb = new WebClientx();
|
|
if (string.IsNullOrEmpty(cookies))
|
|
cookies = GetCookies(url, cookies);
|
|
wb.Timeout = 30;
|
|
wb.Proxy = null;
|
|
wb.AllowAutoRedirect = false;
|
|
//wb.Timeout = 70;
|
|
wb.Headers.Add("Accept", "application/json, text/javascript, */*; q=0.01");
|
|
wb.Headers.Add("Accept-Encoding", "gzip,deflate");
|
|
wb.Headers.Add("Accept-Language", "zh-cn,zh;q=0.8,en-us;q=0.5,en;q=0.3");
|
|
wb.Headers.Add("User-Agent", userAgent);
|
|
wb.Headers.Add("Upgrade-Insecure-Requests", "1");
|
|
//wb.Headers.Add("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8");
|
|
if (!string.IsNullOrEmpty(refere))
|
|
wb.Headers.Add("Referer", refere);
|
|
if (!string.IsNullOrEmpty(cookies))
|
|
wb.Headers.Add("Cookie", cookies);
|
|
//wb.Proxy = null;
|
|
string rehead = wb.Headers.ToString();
|
|
if (url.Contains("mms.pinduoduo.com"))
|
|
wb.Headers.Add("Origin", "http://mms.pinduoduo.com");
|
|
var encode = isUtf8 ? Encoding.UTF8 : Encoding.GetEncoding("gbk");
|
|
byte[] b, postData = encode.GetBytes(data);
|
|
string html, head;
|
|
try
|
|
{
|
|
wb.Headers.Add("Content-Type", "application/json; charset=UTF-8");
|
|
if (string.IsNullOrEmpty(data))
|
|
{
|
|
b = wb.DownloadData(url);
|
|
}
|
|
else
|
|
{
|
|
//wb.Headers.Add("Content-Type", "application/x-www-form-urlencoded");
|
|
wb.Headers.Add("ContentLength", postData.Length.ToString());
|
|
b = wb.UploadData(url, "POST", postData);
|
|
}
|
|
html = encode.GetString(b);
|
|
head = wb.ResponseHeaders.ToString();
|
|
}
|
|
catch (Exception ee)
|
|
{
|
|
html = "提交错误:" + ee.Message;
|
|
head = "";
|
|
}
|
|
return GetHtml.Decode(html);
|
|
}
|
|
|
|
public static string PostFileTaobao(string url, string refere, bool isUtf8, NameValueCollection stringDict,byte[] file)
|
|
{
|
|
string cookies = GetCookies(url, "");
|
|
string html = HttpPostData(url, 30000, "imgfile", "1.jpg", file, stringDict, "", cookies);
|
|
return html;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 发送post请求
|
|
/// </summary>
|
|
/// <param name="url"></param>
|
|
/// <param name="timeOut"></param>
|
|
/// <param name="fileKeyName"></param>
|
|
/// <param name="filePath"></param>
|
|
/// <param name="stringDict"></param>
|
|
/// <returns></returns>
|
|
private static string HttpPostData(string url, int timeOut, string fileKeyName, string fileName, byte[] file, NameValueCollection stringDict, string referer, string cookies = "")
|
|
{
|
|
string responseContent;
|
|
string cookie = BaseClass.CookiesAllString.ContainsKey("taobao.com") ? BaseClass.CookiesAllString["taobao.com"] : "";
|
|
if (!string.IsNullOrEmpty(cookies))
|
|
{
|
|
cookie = cookies;
|
|
}
|
|
var memStream = new MemoryStream();
|
|
var webRequest = (HttpWebRequest)WebRequest.Create(url);
|
|
// 边界符
|
|
var boundary = "----------QkZCM0JGQjYtQzkwRC1CRkU0LUFFQjctMUEyM0M5MkVDMTMz";
|
|
// 边界符
|
|
var beginBoundary = Encoding.ASCII.GetBytes("--" + boundary + "\r\n");
|
|
//var fileStream = new FileStream(filePath, FileMode.Open, FileAccess.Read);
|
|
// 最后的结束符
|
|
var endBoundary = Encoding.ASCII.GetBytes("--" + boundary + "--\r\n");
|
|
|
|
// 设置属性
|
|
webRequest.Method = "POST";
|
|
webRequest.Timeout = timeOut;
|
|
webRequest.Proxy = null;
|
|
webRequest.ReadWriteTimeout = timeOut;
|
|
webRequest.ContentType = "multipart/form-data; boundary=" + boundary;
|
|
if (string.IsNullOrEmpty(referer))
|
|
referer = "https://tadget.taobao.com/redaction/manager.htm";
|
|
webRequest.Referer = referer;
|
|
webRequest.UserAgent = BaseClass.ChromeUserAgent;
|
|
//webRequest.UserAgent = "Mozilla/5.0 (Windows NT 6.1; WOW64; Trident/7.0; rv:11.0) like Gecko";
|
|
webRequest.Headers.Add("Cookie", cookie);
|
|
webRequest.Headers.Add("Origin", "https://www.taobao.com");
|
|
webRequest.Headers.Add("Upgrade-Insecure-Requests", "1");
|
|
webRequest.Headers.Add("Cache-Control", "max-age=0");
|
|
//webRequest.Headers.Add("Cookie", "v=0; cookie2=19bb7096a84354a4c14f57b3b139b358; _tb_token_=371a6e3e53673; existShop=MTQ5NTA4NzEwNQ%3D%3D; skt=07be2c7a4d43d4e3; publishItemObj=Ng%3D%3D; t=cdd5be62cd6b4e78434311371fbd7ff9; uc3=sg2=UtABdWdeGfXD%2FQkzzQhDSLQGa8sMw6MWHGmZA5%2Fz1oY%3D&nk2=G4mgLCefCRJZu5RKow%3D%3D&id2=W8nWsIU9pmPl&vt3=F8dARVDUXtcYdighsV4%3D&lg2=VFC%2FuZ9ayeYq2g%3D%3D; tracknick=xiaotui930904; _cc_=UIHiLt3xSw%3D%3D; tg=0; thw=cn; ali_ab=36.7.115.240.1486373819164.2; miid=805014732159802464; mt=np=&ci=1_1&cyk=2_0; hng=CN%7Czh-CN%7CCNY; cna=FBaXEKHXWGsCASQ5jXreM7Bn; l=Alpa9EIFIfaqKZPIW3nvwNBw6g58A95l; isg=AoGB_EtuvM235dDxcXm4k6uxmM2obfWgjhNWjuPW9AjnyqCcK_uCcC2I-ody; lgc=xiaotui930904; uss=BxExuOuBMGTSmmLusncTQzrc54qNGyvc44m3KpvMw%2FDqvz12lH2jkCfx; _m_user_unitinfo_=unit|unsz; _m_h5_tk=0e98a920393ab7ef74949cb428e8cbf8_1495072723582; _m_h5_tk_enc=c01cbddf709302868d28a398ddc7a464; _m_unitapi_v_=1492572565585; uc1=cookie14=UoW%2BvfobS%2FYyFQ%3D%3D&lng=zh_CN&cookie16=UtASsssmPlP%2Ff1IHDsDaPRu%2BPw%3D%3D&existShop=true&cookie21=UIHiLt3xSixwH1aenGUFEQ%3D%3D&tag=8&cookie15=WqG3DMC9VAQiUQ%3D%3D&pas=0; sg=482; cookie1=AVZ7NzilkILAckSZh3aH1rY3cLn%2F1CTS%2FTys%2FR09hPk%3D; unb=802158228; _l_g_=Ug%3D%3D; _nk_=xiaotui930904; cookie17=W8nWsIU9pmPl; JSESSIONID=3667ED995D0FA3DF2C4B9D2848FBECFB; apushcff39d705ee654f2389a8c5fb80067dd=%7B%22ts%22%3A1495087171963%2C%22parentId%22%3A1495087120835%7D");
|
|
//webRequest.Headers.Add("X-Requested-With", "ShockwaveFlash/23.9.9.999");
|
|
//webRequest.Headers.Add("x-flash-version", "25,0,0,148");
|
|
string head = webRequest.Headers.ToString();
|
|
// 写入文件
|
|
string filePartHeader =
|
|
"Content-Disposition: form-data; name=\"{0}\"; filename=\"{1}\"\r\n" +
|
|
"Content-Type: application/octet-stream\r\n\r\n";
|
|
if (url.Contains("s.taobao.com/image"))
|
|
{
|
|
filePartHeader =
|
|
"Content-Disposition: form-data; name=\"{0}\"; filename=\"{1}\"\r\n" +
|
|
"Content-Type: image/jpeg\r\n\r\n";
|
|
}
|
|
var header = string.Format(filePartHeader, fileKeyName, fileName);
|
|
var headerbytes = Encoding.UTF8.GetBytes(header);
|
|
|
|
memStream.Write(beginBoundary, 0, beginBoundary.Length);
|
|
memStream.Write(headerbytes, 0, headerbytes.Length);
|
|
|
|
//while ((bytesRead = fileStream.Read(buffer, 0, buffer.Length)) != 0)
|
|
//{
|
|
// memStream.Write(buffer, 0, bytesRead);
|
|
//}
|
|
memStream.Write(file, 0, file.Length);
|
|
|
|
// 写入字符串的Key
|
|
var stringKeyHeader = "\r\n--" + boundary +
|
|
"\r\nContent-Disposition: form-data; name=\"{0}\"" +
|
|
"\r\n\r\n{1}\r\n";
|
|
|
|
foreach (byte[] formitembytes in from string key in stringDict.Keys
|
|
select string.Format(stringKeyHeader, key, stringDict[key])
|
|
into formitem
|
|
select Encoding.UTF8.GetBytes(formitem))
|
|
{
|
|
memStream.Write(formitembytes, 0, formitembytes.Length);
|
|
}
|
|
|
|
// 写入最后的结束边界符
|
|
memStream.Write(endBoundary, 0, endBoundary.Length);
|
|
|
|
webRequest.ContentLength = memStream.Length;
|
|
|
|
var requestStream = webRequest.GetRequestStream();
|
|
|
|
memStream.Position = 0;
|
|
var tempBuffer = new byte[memStream.Length];
|
|
memStream.Read(tempBuffer, 0, tempBuffer.Length);
|
|
memStream.Close();
|
|
|
|
requestStream.Write(tempBuffer, 0, tempBuffer.Length);
|
|
requestStream.Close();
|
|
|
|
var httpWebResponse = (HttpWebResponse)webRequest.GetResponse();
|
|
|
|
using (var httpStreamReader = new StreamReader(httpWebResponse.GetResponseStream(),
|
|
Encoding.GetEncoding("utf-8")))
|
|
{
|
|
responseContent = httpStreamReader.ReadToEnd();
|
|
}
|
|
|
|
httpWebResponse.Close();
|
|
webRequest.Abort();
|
|
|
|
return responseContent;
|
|
}
|
|
|
|
public static string UploadBaidu(string url)
|
|
{
|
|
string userAgent = string.IsNullOrEmpty(BaseClass.ChromeUserAgent) ? BaseClass.UserAgent : BaseClass.ChromeUserAgent;
|
|
HttpWebResponse response = null;
|
|
try
|
|
{
|
|
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
|
|
request.Method = "GET";
|
|
request.KeepAlive = true;
|
|
request.Accept = "*/*";
|
|
request.Headers.Add("is_xhr", @"1");
|
|
request.Headers.Add("X-Requested-With", @"XMLHttpRequest");
|
|
request.Headers.Add("is_referer", @"https://www.baidu.com/s?wd=%E6%9C%AC%E6%9C%BAip%E5%9C%B0%E5%9D%80%E6%9F%A5%E8%AF%A22");
|
|
request.UserAgent = userAgent;
|
|
request.Headers.Add("is_pbs", @"%E6%9C%AC%E6%9C%BAip%E5%9C%B0%E5%9D%80%E6%9F%A5%E8%AF%A2");
|
|
request.Referer = "https://www.baidu.com/s?wd=%E6%9C%AC%E6%9C%BAip%E5%9C%B0%E5%9D%80%E6%9F%A5%E8%AF%A2";
|
|
request.Headers.Set(HttpRequestHeader.AcceptEncoding, "gzip, deflate, br");
|
|
request.Headers.Set(HttpRequestHeader.AcceptLanguage, "zh-CN,zh;q=0.9");
|
|
|
|
response = (HttpWebResponse)request.GetResponse();
|
|
}
|
|
catch (WebException e)
|
|
{
|
|
if (e.Status == WebExceptionStatus.ProtocolError) response = (HttpWebResponse)e.Response;
|
|
else return "";
|
|
}
|
|
catch (Exception)
|
|
{
|
|
if (response != null) response.Close();
|
|
return "";
|
|
}
|
|
using (Stream responseStream = response.GetResponseStream())
|
|
{
|
|
Stream streamToRead = responseStream;
|
|
if (response.ContentEncoding.ToLower().Contains("gzip"))
|
|
{
|
|
streamToRead = new GZipStream(streamToRead, CompressionMode.Decompress);
|
|
}
|
|
else if (response.ContentEncoding.ToLower().Contains("deflate"))
|
|
{
|
|
streamToRead = new DeflateStream(streamToRead, CompressionMode.Decompress);
|
|
}
|
|
using (StreamReader streamReader = new StreamReader(streamToRead, Encoding.UTF8))
|
|
{
|
|
return streamReader.ReadToEnd();
|
|
}
|
|
}
|
|
return "";
|
|
}
|
|
}
|
|
}
|