http://www.sufeinet.com/plugin.php?id=keke_group

苏飞论坛

 找回密码
 马上注册

QQ登录

只需一步,快速开始

分布式系统框架(V2.0) 轻松承载百亿数据,千万流量!讨论专区 - 源码下载 - 官方教程

HttpHelper爬虫框架(V2.7-含.netcore) HttpHelper官方出品,爬虫框架讨论区 - 源码下载 - 在线测试和代码生成

HttpHelper爬虫类(V2.0) 开源的爬虫类,支持多种模式和属性 源码 - 代码生成器 - 讨论区 - 教程- 例子

查看: 8555|回复: 1

[求助] 模拟上传excel文件报错

[复制链接]
发表于 2023-8-30 11:31:42 | 显示全部楼层 |阅读模式
同一个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






1. 开通SVIP会员,免费下载本站所有源码,不限次数据,不限时间
2. 加官方QQ群,加官方微信群获取更多资源和帮助
3. 找站长苏飞做网站、商城、CRM、小程序、App、爬虫相关、项目外包等点这里
发表于 2023-9-4 11:01:32 | 显示全部楼层
看着好像差不多,多加一句 PostEncoding = Encoding.UTF8,
您需要登录后才可以回帖 登录 | 马上注册

本版积分规则

QQ|手机版|小黑屋|手机版|联系我们|关于我们|广告合作|苏飞论坛 ( 豫ICP备18043678号-2)

GMT+8, 2024-11-24 12:18

© 2014-2021

快速回复 返回顶部 返回列表