拍单功能继续优化
This commit is contained in:
1 parent
29042424dc
commit
34c51c6fcd
64 files changed
+7138
-305
No files matched your search
@@ -0,0 +1,64 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.IO.Compression;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using System.Text;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Work._29Tools.BLL
|
||||
{
|
||||
public class HttpResponseBLL
|
||||
{
|
||||
|
||||
public static string ReadResponse(HttpWebResponse response, Encoding encoding = null)
|
||||
{
|
||||
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);
|
||||
}
|
||||
if (encoding == null) encoding = Encoding.UTF8;
|
||||
using (StreamReader streamReader = new StreamReader(streamToRead, encoding))
|
||||
{
|
||||
return streamReader.ReadToEnd();
|
||||
}
|
||||
}
|
||||
}
|
||||
public static void WriteMultipartBodyToRequest(HttpWebRequest request, string body)
|
||||
{
|
||||
string[] multiparts = Regex.Split(body, @"<!>");
|
||||
byte[] bytes;
|
||||
using (MemoryStream ms = new MemoryStream())
|
||||
{
|
||||
foreach (string part in multiparts)
|
||||
{
|
||||
if (File.Exists(part))
|
||||
{
|
||||
bytes = File.ReadAllBytes(part);
|
||||
}
|
||||
else
|
||||
{
|
||||
bytes = System.Text.Encoding.UTF8.GetBytes(part.Replace("\r\n", "\n").Replace("\r", "\n").Replace("\n", "\r\n"));
|
||||
}
|
||||
|
||||
ms.Write(bytes, 0, bytes.Length);
|
||||
}
|
||||
|
||||
request.ContentLength = ms.Length;
|
||||
using (Stream stream = request.GetRequestStream())
|
||||
{
|
||||
ms.WriteTo(stream);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user