修改云端数据 代码改为异步,导入成功提示
This commit is contained in:
1 parent
de9cd4ae65
commit
4fdcc94a91
5 files changed
+176
-70
No files matched your search
+83
-7
@@ -1250,13 +1250,89 @@ Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrom
|
||||
}
|
||||
|
||||
}
|
||||
/// <summary>
|
||||
/// post 数据
|
||||
/// </summary>
|
||||
/// <param name="url"></param>
|
||||
/// <param name="byteData"></param>
|
||||
/// <returns></returns>
|
||||
public static string PostUtf8(string url, byte[] byteData)
|
||||
public static async Task<string> PostUtf8Async(string url, string postData, string contentType = "", int? timeOut = null)
|
||||
{
|
||||
|
||||
bool isError = false;
|
||||
string[] l = UserAgent.Split('\n');
|
||||
reTry:
|
||||
try
|
||||
{
|
||||
string codeType = "utf-8";
|
||||
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
|
||||
request.UserAgent = l[new Random(Guid.NewGuid().GetHashCode()).Next(l.Length)].Trim();
|
||||
byte[] byteData = Encoding.GetEncoding(codeType).GetBytes(postData);
|
||||
request.Method = "POST";
|
||||
request.Accept = "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8";
|
||||
request.Timeout = BaseClass.TimeOut * 1000;
|
||||
request.ReadWriteTimeout = BaseClass.TimeOut * 1000;
|
||||
if (timeOut != null)
|
||||
{
|
||||
request.Timeout = timeOut.Value * 1000;
|
||||
request.ReadWriteTimeout = timeOut.Value * 1000;
|
||||
}
|
||||
request.Proxy = null;
|
||||
request.ContentType = "application/x-www-form-urlencoded; charset=" + codeType;
|
||||
//if(BaseClass.SaLevel > 0)
|
||||
{
|
||||
//260306 采用GZip/deflate压缩
|
||||
//request.Headers.Set(HttpRequestHeader.AcceptEncoding, "gzip, deflate, br, zstd");
|
||||
request.Headers.Set(HttpRequestHeader.AcceptEncoding, "gzip, deflate");
|
||||
}
|
||||
if (url.StartsWith("https://openapi.jinritemai.com/"))
|
||||
{
|
||||
request.Headers.Add("X-USE-BOE", "1");
|
||||
request.Headers.Add("Origin-From", "djt_prod");
|
||||
request.Headers.Add("djt_prod", "boe_time_sku");
|
||||
}
|
||||
if (!string.IsNullOrEmpty(contentType))
|
||||
{
|
||||
request.ContentType = contentType;
|
||||
}
|
||||
request.ContentLength = byteData.Length;
|
||||
request.Referer = url;
|
||||
request.CookieContainer = new CookieContainer();
|
||||
request.AllowAutoRedirect = false;
|
||||
using (Stream requestStream = await request.GetRequestStreamAsync())
|
||||
{
|
||||
requestStream.Write(byteData, 0, byteData.Length);
|
||||
}
|
||||
HttpWebResponse response = (HttpWebResponse) await request.GetResponseAsync();
|
||||
|
||||
Stream receiveStream = response.GetResponseStream();
|
||||
StreamReader readStream = new StreamReader(receiveStream, Encoding.GetEncoding(codeType));
|
||||
|
||||
//if (BaseClass.SaLevel == 0)
|
||||
//{
|
||||
// return readStream.ReadToEnd().Trim();
|
||||
//}
|
||||
//else
|
||||
{
|
||||
//260306 超管采用GZip/deflate压缩
|
||||
//Thread.Sleep(50);
|
||||
return GetProxyHtml.ReadResponse(response);
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
LogSave.Add(e.ToString());
|
||||
//if (!isError)
|
||||
//{
|
||||
// isError = true;
|
||||
// goto reTry;
|
||||
//}
|
||||
Thread.Sleep(50);
|
||||
return "";
|
||||
}
|
||||
|
||||
}
|
||||
/// <summary>
|
||||
/// post 数据
|
||||
/// </summary>
|
||||
/// <param name="url"></param>
|
||||
/// <param name="byteData"></param>
|
||||
/// <returns></returns>
|
||||
public static string PostUtf8(string url, byte[] byteData)
|
||||
{
|
||||
WebClientx webClient = new WebClientx();
|
||||
try
|
||||
|
||||
Reference in new issue
Block a user