12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879 |
- using System;
- using System.Text;
- using System.IO;
- namespace Alipay.EasySDK.Kernel.Util
- {
-
-
-
- public static class MultipartUtil
- {
-
-
-
-
-
- public static byte[] GetEntryBoundary(string boundary)
- {
- return Encoding.UTF8.GetBytes("\r\n--" + boundary + "\r\n");
- }
-
-
-
-
-
- public static byte[] GetEndBoundary(string boundary)
- {
- return Encoding.UTF8.GetBytes("\r\n--" + boundary + "--\r\n");
- }
-
-
-
-
-
-
- public static byte[] GetTextEntry(string fieldName, string fieldValue)
- {
- string entry = "Content-Disposition:form-data;name=\""
- + fieldName
- + "\"\r\nContent-Type:text/plain\r\n\r\n"
- + fieldValue;
- return AlipayConstants.DEFAULT_CHARSET.GetBytes(entry);
- }
-
-
-
-
-
-
- public static byte[] GetFileEntry(String fieldName, String filePath)
- {
- ArgumentValidator.CheckArgument(File.Exists(filePath),
- Path.GetFullPath(filePath) + "文件不存在");
- ArgumentValidator.CheckArgument(Path.GetFileName(filePath).Contains("."),
- "文件名必须带上正确的扩展名");
- String entry = "Content-Disposition:form-data;name=\""
- + fieldName
- + "\";filename=\""
- + Path.GetFileName(filePath)
- + "\"\r\nContent-Type:application/octet-stream"
- + "\r\n\r\n";
- return AlipayConstants.DEFAULT_CHARSET.GetBytes(entry);
- }
-
-
-
-
-
- public static void WriteToStream(Stream stream, byte[] content)
- {
- stream.Write(content, 0, content.Length);
- }
- }
- }
|