|
楼主 |
发表于 2016-9-1 15:46:59
|
显示全部楼层
//上传图片
#region 变量
byte[] UploadBuffers = null;
string BoundStr = "------WebKitFormBoundarynBAqI6TyFak1jwN1";
StringBuilder UploadBuf = new StringBuilder();
#endregion
#region 头部数据
UploadBuf.Append("content-type:multipart/form-data; boundary="+ BoundStr);
byte[] HeadBytes = Encoding.ASCII.GetBytes(UploadBuf.ToString());
#endregion
#region 图片数据
byte[] PicBytes = ImageToBytesFromFilePath(@"C:\Project\128.png");
#endregion
#region 尾部数据
UploadBuf.Clear();
UploadBuf.Append(BoundStr + "\r\n");
UploadBuf.Append(@"Content-Disposition: form-data; name=""name""" + "\r\n\r\n\r\n");
UploadBuf.Append("128.png" + "\r\n");
UploadBuf.Append(BoundStr + "\r\n" + @"Content-Disposition: form-data; name=""file""; filename=""128.png""" + "\r\n");
UploadBuf.Append("Content-Type: image/png" +"\r\n\r\n\r\n");
UploadBuf.Append(BoundStr + "--");
byte[] TailBytes = Encoding.ASCII.GetBytes(UploadBuf.ToString());
#endregion
#region 数组拼接
UploadBuffers = ComposeArrays(HeadBytes, PicBytes);
UploadBuffers = ComposeArrays(UploadBuffers, TailBytes);
#endregion
#region 上传
item = new HttpItem()
{
URL = "https://stream.taobao.com/api/upload.api?appkey=tu&phone=false&folderId=172751275624965728&_input_charset=utf-8&watermark=false",
Method = "POST",
ContentType = "multipart/form-data; boundary=" + BoundStr.Substring(2),
Referer = "https://stream.taobao.com/plugin.htm?appkey=tu&single=true&tab=list&pageSize=10&maxNum=-1&ver=1.0.0",
PostDataType = PostDataType.Byte,
Cookie = cookie,
Encoding = Encoding.UTF8,
PostdataByte = UploadBuffers
};
var result = http.GetHtml(item);
#endregion |
|