|
HttpItem item = new HttpItem()
{
URL = WebInfo.UploadUrl, //URL 必需项
Encoding = Encoding.UTF8, //编码格式(utf-8,gb2312,gbk) 可选项 默认类会自动识别
PostEncoding = Encoding.UTF8,
Method = "post", //URL 可选项 默认为Get
IsToLower = false, //得到的HTML代码是否转成小写 可选项默认转小写
Cookie = $"{WebInfo.loginInfo.data.token};sidebarStatus=0", //字符串Cookie 可选项
UserAgent =
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.88 Safari/537.36",
Accept = "application/json, text/plain, */*",
ContentType = "multipart/form-data; boundary=----WebKitFormBoundary79HpdlA1IVWZnKxx",
Connectionlimit = 1024,
PostDataType = PostDataType.Byte,
ResultType = ResultType.String,
};
第一种方案:改了下源码 循环提交
byte[] boundaryBytes = Encoding.UTF8.GetBytes("----WebKitFormBoundary79HpdlA1IVWZnKxx\r\n");
byte[] postHeaderBytes = Encoding.UTF8.GetBytes("Content-Disposition: form-data; name=\"file\"; filename=\"image.png\"\r\n");
byte[] postHeaderBytes1 = Encoding.UTF8.GetBytes("Content-Type: image/png\r\n");
byte[] postHeaderBytes2 = Encoding.UTF8.GetBytes("Content-Disposition: form-data; name=\"type\"\r\n");
byte[] typeBytes = Encoding.UTF8.GetBytes(type);
item.PostdataByte = new[]
{
boundaryBytes, postHeaderBytes, postHeaderBytes1, imgBase64Bytes, boundaryBytes, postHeaderBytes2, typeBytes,
boundaryBytes
};
第二种:拼接字符串
//// string body = $@"----WebKitFormBoundary79HpdlA1IVWZnKxx
////Content-Disposition: form-data; name=""file""; filename=""image.png""
////Content-Type: image/png
////{ImageHelper.ImgToBase64(img)}
////----WebKitFormBoundary79HpdlA1IVWZnKxx
////Content-Disposition: form-data; name=""type""
////{type}
////----WebKitFormBoundary79HpdlA1IVWZnKxx";
// string body = $@"{{
// file: ""{ImageHelper.ImgToBase64(img)}"",
// type:""{type}""
//}}";
//item.Postdata = body;
登陆都可以,但是提交图片就不行,求教怎么办?
|
|