同一个EXCEL文件 在网站上正常提交的时候是没有问题的
利用httphelper 把文件转为byte再上传 时则报错
服务器返回错误:org.apache.tomcat.util.http.fileupload.FileUploadException: Header section has more than 10240 bytes (maybe it is not properly terminated)
[C#] 纯文本查看 复制代码 string filename = "1.xlsx";
//Byte[] buffer = System.IO.File.ReadAllBytes(Server.MapPath("~/") + "upload/import/" + filename);
FileStream fs = new FileStream(Server.MapPath("~/") + "upload/import/" + filename, FileMode.Open, FileAccess.Read);
byte[] buffer = new byte[(int)fs.Length];
fs.Read(buffer, 0, buffer.Length);
fs.Close();
string boundary = "WebKitFormBoundary" + FBA.Logistics.Utils.GenerateRandomNumber(16);// Guid.NewGuid().ToString("N").Substring(16);
Dictionary<string, object> postdata = new Dictionary<string, object>();
//FileParameter 是拼接文件流
FBA.Logistics.FileParameter val = new FBA.Logistics.FileParameter(buffer, filename, "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
postdata.Add("file", val);
byte[] formData =FBA.Logistics. Utils.CreateFormData(postdata, boundary);
string result =System.Text. Encoding.UTF8.GetString(formData);
var item = new HttpItem()
{
Accept = "*/*",
URL = "http://tms-api.ec-print.cn/order/goodsInfoImport?customerCode=",
Method = "POST",
Host = "tms-api.ec-print.cn",
Referer = "https://oms.szylyn.net/",
ContentType = "multipart/form-data; boundary=----" + boundary,
PostDataType = PostDataType.Byte,
PostdataByte = formData,
};
item.Header.Add("Access-Channel-Headers", "ADMIN");
//item.Header.Add("token", token);
item.Header.Add("Origin", "http://oms.szylyn.net");
item.SecurityProtocol = SecurityProtocolType.Ssl3
| SecurityProtocolType.Tls
| SecurityProtocolType.Tls11
| SecurityProtocolType.Tls12;
HttpHelper helper = new HttpHelper();
var res = helper.GetHtml(item);
Response.Write(res.Html);
请求头
[color=var(--color-text-primary)]Accept:
*/*
[color=var(--color-text-primary)]Accept-Encoding:
gzip, deflate
[color=var(--color-text-primary)]Accept-Language:
zh-TW,zh;q=0.9,en-US;q=0.8,en;q=0.7,zh-CN;q=0.6,ja;q=0.5
[color=var(--color-text-primary)]Access-Channel-Headers:
ADMIN
[color=var(--color-text-primary)]Connection:
keep-alive
[color=var(--color-text-primary)]Content-Length:
16539
[color=var(--color-text-primary)]Content-Type:
multipart/form-data; boundary=----WebKitFormBoundaryHDlCc5aXXp1WKPiE
[color=var(--color-text-primary)]Host:
tms-api.ec-print.cn
[color=var(--color-text-primary)]Origin:
http://oms.szylyn.net
[color=var(--color-text-primary)]Referer:
http://oms.szylyn.net/
[color=var(--color-text-primary)]Token:
hnfsu.tms.token::eyJhbGciOiJIUzI1NiJ9.eyJzdWIiOiIxNTMzNjMiLCJpYXQiOjE2OTMwMjE2MjcsImxvZ2luLXVzZXItaWQiOjE1MzM2MywidXNlcm5hbWUiOiJTVFIxNjgiLCJsb2dpbi1jb21wYW55LWNvZGUiOiIiLCJsb2dpbi1jaGFubmVsIjoiV0VCIn0.H6DN4QQ83a0m3yDqzKf4PVV42H99RPu7zsUr1X131X8
[color=var(--color-text-primary)]User-Agent:
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/116.0.0.0 Safari/537.36
|