1097 lines
51 KiB
C#
1097 lines
51 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Net;
|
|
using System.Text;
|
|
using AllBase;
|
|
using System.Threading.Tasks;
|
|
using System.Threading;
|
|
using System.IO;
|
|
using System.Collections.Specialized;
|
|
using System.IO.Compression;
|
|
using Work.Tips;
|
|
using CefSharp;
|
|
|
|
namespace Work
|
|
{
|
|
public class GetPostTaobaoHtml
|
|
{
|
|
public static TokenForm tokenForm;
|
|
|
|
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 domain = GetHtml.GetDomain(url);
|
|
string mainDomain = GetHtml.GetMainDomain(domain);
|
|
string cookies = "";
|
|
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.IsDelete = true;
|
|
wb.Timeout = 30;
|
|
|
|
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 "";
|
|
}
|
|
}
|
|
|
|
|
|
/// <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)
|
|
{
|
|
return UploadTaobaoPost(url, refere, isUtf8, "", false, "");
|
|
}
|
|
|
|
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 UploadTaobao(string url, string refere, bool isUtf8, string cookies)
|
|
{
|
|
return UploadTaobaoPost(url, refere, isUtf8, "", false, cookies);
|
|
}
|
|
|
|
public static string UploadTaobaoPost(string url, string refere, bool isUtf8, string data, bool isPost)
|
|
{
|
|
return UploadTaobaoPost(url, refere, isUtf8, data, isPost, "");
|
|
}
|
|
|
|
public static string UploadTaobaoCookiePost(string url, string refere, bool isUtf8, string data, bool isPost, string cookies)
|
|
{
|
|
return UploadTaobaoPost(url, refere, isUtf8, data, isPost, 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;
|
|
}
|
|
/// <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)
|
|
{
|
|
try
|
|
{
|
|
cookies = GetCookies(url, cookies);
|
|
string userAgent = BaseClass.ChromeUserAgent;
|
|
if (url.Contains("mms.pinduoduo.com/") && cookies.Contains("windows"))
|
|
{
|
|
userAgent = BaseClass.PddShopChromeUserAgent;
|
|
}
|
|
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 (url.Contains("robot/shop/orders/shipping") || url.Contains("mars/shop/orderDetail") || url.Contains("latitude/order/orderAddress")
|
|
// || url.Contains("mars/shop/recentOrderList") || url.Contains("mars/shop/orderList")
|
|
// || url.Contains("mars/shop/sendSingleGroupCard") || url.Contains("mars/shop/orderAddressDetail")
|
|
// || url.Contains("shop/address/update") || url.Contains("order/address/update") || url.Contains("pizza/order/updateAddress")
|
|
// || url.Contains("mars/mobile/queryMobileByOrderSn")
|
|
// || url.Contains("mercury/afterSales/list") || url.Contains("mars/shop/queryMallWaitGroupOrders")
|
|
// || url.Contains("pizza/order/remark/query")
|
|
// || url.Contains("mms/order/merge/ship")
|
|
// || url.Contains("vodka/v2/mms/pc/offSale")
|
|
// || url.Contains("newjersy/api/innerMessage/queryMsgListForMerchant")
|
|
// || url.Contains("fopen/order/prepare")
|
|
// || url.Contains("pifa/order/pageQuery")
|
|
// || url.Contains("genji/gosling/mallViolationAppeal/query/queryAppealRecord"))
|
|
if (url.Contains("mms.pinduoduo.com/"))
|
|
{
|
|
//string AntiContent = GetHtml.Utf8("http://nano.qixiaoke.com/123.txt");
|
|
//wb.Headers.Add("anti-content", AntiContent);
|
|
if (tokenForm != null)
|
|
{
|
|
string token = "";
|
|
if (url.Contains("mms.pinduoduo.com/") && cookies.Contains("windows"))
|
|
{
|
|
token = GetCodex(cookies, refere);
|
|
}
|
|
else
|
|
{
|
|
token = tokenForm.GetGoken();
|
|
}
|
|
if (!string.IsNullOrEmpty(token))
|
|
{
|
|
wb.Headers.Add("anti-content", token);
|
|
}
|
|
else
|
|
{
|
|
wb.Headers.Add("anti-content", BaseClass.AntiContent);
|
|
}
|
|
|
|
}
|
|
else
|
|
{
|
|
wb.Headers.Add("anti-content", BaseClass.AntiContent);
|
|
}
|
|
if (url.Contains("mercury/afterSales/list"))
|
|
{
|
|
wb.Headers.Add("VerifyAuthToken", BaseClass.verify_auth_token);
|
|
}
|
|
}
|
|
|
|
if (url.Contains("proxy/api/api/oak/integration/") && !string.IsNullOrEmpty(BaseClass.verify_auth_token))
|
|
{
|
|
wb.Headers.Add("VerifyAuthToken", BaseClass.verify_auth_token);
|
|
}
|
|
|
|
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"]);
|
|
}
|
|
}
|
|
if (data.Contains("0aoanti_content"))
|
|
{
|
|
string token = AllBase.Helper.HttpHelper.GetAntiContent0ap(cookies, userAgent, refere);
|
|
data = data.Replace("0aoanti_content", token);
|
|
}
|
|
|
|
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", BaseClass.ChromeUserAgent);
|
|
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 GetCodex(string cookies, string refere)
|
|
{
|
|
//string userAgent = BaseClass.ChromeCookies;
|
|
//if (cookies.Contains("windows"))
|
|
string userAgent = BaseClass.PddShopChromeUserAgent;
|
|
var xxx = tokenForm.GetAntiContent0ao_v3(cookies, userAgent, refere);
|
|
string codex = xxx.Result;
|
|
return codex;
|
|
}
|
|
|
|
#region 通过接口获取商品详情专用
|
|
/// <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 UploadTaobaoPostx(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 (url.Contains("proxy/api/api/oak/integration/") && !string.IsNullOrEmpty(BaseClass.verify_auth_token_prodetails))
|
|
{
|
|
wb.Headers.Add("VerifyAuthToken", BaseClass.verify_auth_token_prodetails);
|
|
}
|
|
|
|
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 "";
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
|
|
public static string GetUrl(string url, string refere, bool isUtf8, string data)
|
|
{
|
|
try
|
|
{
|
|
string domain = GetHtml.GetDomain(url);
|
|
string mainDomain = GetHtml.GetMainDomain(domain);
|
|
string cookies = "";
|
|
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);
|
|
head = wb.Headers.ToString();
|
|
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 "";
|
|
}
|
|
}
|
|
|
|
/// <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.IsNullOrEmpty(BaseClass.ChromeCookies) ? IECookies.GetCookieByWebBrowser(url) : BaseClass.ChromeCookies;
|
|
string userAgent = string.IsNullOrEmpty(BaseClass.ChromeUserAgent) ? BaseClass.UserAgent : BaseClass.ChromeUserAgent;
|
|
WebClientx wb = new WebClientx();
|
|
|
|
wb.Timeout = 30;
|
|
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);
|
|
//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))
|
|
{
|
|
b = wb.DownloadData(url);
|
|
}
|
|
else
|
|
{
|
|
//wb.Headers.Add("Content-Type", "application/x-www-form-urlencoded");
|
|
wb.Headers.Add("Content-Type", "application/json; charset=UTF-8");
|
|
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 html;
|
|
}
|
|
|
|
|
|
#region 风控
|
|
/// <summary>
|
|
/// json提交数据--风控解密专用
|
|
/// </summary>
|
|
/// <param name="url"></param>
|
|
/// <param name="refere"></param>
|
|
/// <param name="isUtf8"></param>
|
|
/// <param name="data"></param>
|
|
/// <returns></returns>
|
|
public static string GetJsonPostx(string url, string refere, bool isUtf8, string data, string verifyAuthToken)
|
|
{
|
|
string cookies = string.IsNullOrEmpty(BaseClass.ChromeCookies) ? IECookies.GetCookieByWebBrowser(url) : BaseClass.ChromeCookies;
|
|
string userAgent = string.IsNullOrEmpty(BaseClass.ChromeUserAgent) ? BaseClass.UserAgent : BaseClass.ChromeUserAgent;
|
|
WebClientx wb = new WebClientx();
|
|
|
|
wb.Timeout = 30;
|
|
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(verifyAuthToken))
|
|
{
|
|
wb.Headers.Add("X-PDD-VerifyAuthToken", verifyAuthToken);
|
|
}
|
|
|
|
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))
|
|
{
|
|
b = wb.DownloadData(url);
|
|
}
|
|
else
|
|
{
|
|
//wb.Headers.Add("Content-Type", "application/x-www-form-urlencoded");
|
|
wb.Headers.Add("Content-Type", "application/json; charset=UTF-8");
|
|
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 html;
|
|
}
|
|
#endregion
|
|
|
|
public static string GetJsonPost(string url, string refere, bool isUtf8, string data, string cookies)
|
|
{
|
|
return GetJsonPost(url, refere, isUtf8, data, cookies, "");
|
|
}
|
|
|
|
public static string GetJsonPostByProxy(string url, string refere, bool isUtf8, string data, string cookies)
|
|
{
|
|
string urlx = "http://47.112.221.243/API/spe_get/?token=early&u=1";
|
|
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;
|
|
if (url.Contains("mms.pinduoduo.com/") && cookies.Contains("windows"))
|
|
{
|
|
userAgent = BaseClass.PddShopChromeUserAgent;
|
|
}
|
|
WebClientx wb = new WebClientx();
|
|
if (string.IsNullOrEmpty(cookies))
|
|
cookies = GetCookies(url, cookies);
|
|
wb.Timeout = 70;
|
|
|
|
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 (url.Contains("robot/shop/orders/shipping") || url.Contains("mars/shop/orderDetail") || url.Contains("latitude/order/orderAddress")
|
|
// || url.Contains("mars/shop/recentOrderList") || url.Contains("mars/shop/orderList")
|
|
// || url.Contains("mars/shop/sendSingleGroupCard") || url.Contains("mars/shop/orderAddressDetail")
|
|
// || url.Contains("shop/address/update") || url.Contains("order/address/update") || url.Contains("pizza/order/updateAddress")
|
|
// || url.Contains("mars/mobile/queryMobileByOrderSn")
|
|
// || url.Contains("mercury/afterSales/list") || url.Contains("mars/shop/queryMallWaitGroupOrders")
|
|
// || url.Contains("pizza/order/remark/query")
|
|
// || url.Contains("mms/order/merge/ship")
|
|
// || url.Contains("vodka/v2/mms/pc/offSale")
|
|
// || url.Contains("newjersy/api/innerMessage/queryMsgListForMerchant")
|
|
// || url.Contains("fopen/order/prepare")
|
|
// || url.Contains("pifa/order/pageQuery")
|
|
// || url.Contains("genji/gosling/mallViolationAppeal/query/queryAppealRecord"))
|
|
if (url.Contains("mms.pinduoduo.com/"))
|
|
{
|
|
//string AntiContent = GetHtml.Utf8("http://nano.qixiaoke.com/123.txt");
|
|
//wb.Headers.Add("anti-content", AntiContent);
|
|
if (tokenForm != null)
|
|
{
|
|
string token = "";
|
|
if (url.Contains("mms.pinduoduo.com/") && cookies.Contains("windows"))
|
|
{
|
|
token = GetCodex(cookies, refere);
|
|
}
|
|
else
|
|
{
|
|
token = tokenForm.GetGoken();
|
|
}
|
|
if (!string.IsNullOrEmpty(token))
|
|
{
|
|
wb.Headers.Add("anti-content", token);
|
|
}
|
|
else
|
|
{
|
|
wb.Headers.Add("anti-content", BaseClass.AntiContent);
|
|
}
|
|
|
|
}
|
|
else
|
|
{
|
|
wb.Headers.Add("anti-content", BaseClass.AntiContent);
|
|
}
|
|
if (url.Contains("mercury/afterSales/list"))
|
|
{
|
|
wb.Headers.Add("VerifyAuthToken", BaseClass.verify_auth_token);
|
|
}
|
|
}
|
|
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.AddDays(10),
|
|
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;
|
|
}
|
|
|
|
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 (sCookies.Length == 0)
|
|
{
|
|
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);
|
|
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 "";
|
|
}
|
|
}
|
|
|
|
#region 搜同款用
|
|
/// <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>
|
|
public static string HttpPostData(string url, int timeOut, string fileKeyName, string fileName, byte[] file, NameValueCollection stringDict, string referer, string cookies = "")
|
|
{
|
|
string responseContent = string.Empty;
|
|
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;
|
|
|
|
try
|
|
{
|
|
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();
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
}
|
|
|
|
|
|
try
|
|
{
|
|
var httpWebResponse = (HttpWebResponse)webRequest.GetResponse();
|
|
|
|
using (var httpStreamReader = new StreamReader(httpWebResponse.GetResponseStream(),
|
|
Encoding.GetEncoding("utf-8")))
|
|
{
|
|
responseContent = httpStreamReader.ReadToEnd();
|
|
}
|
|
httpWebResponse.Close();
|
|
}
|
|
catch (Exception)
|
|
{ }
|
|
finally
|
|
{
|
|
webRequest.Abort();
|
|
}
|
|
return responseContent;
|
|
}
|
|
#endregion
|
|
|
|
#region 获取ip
|
|
|
|
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 "";
|
|
}
|
|
|
|
|
|
#endregion
|
|
}
|
|
}
|