|
1金钱
本帖最后由 speed2018 于 2014-7-29 12:43 编辑
为什么总是提示未将对象设置到实例,是哪里有问题你呢?
cookie 很简单,不会有问题。
下面是代码:
#region
//头部
string boundary = "----------cH2Ef1Ij5Ij5gL6GI3ei4Ij5Ef1gL6";
StringBuilder sb = new StringBuilder();
sb.AppendLine("--" + boundary);
sb.AppendLine("Content-Disposition: form-data; name=\"Filename\"; \r\n\r\n1234a.jpg");
sb.AppendLine("--" + boundary);
sb.AppendLine("Content-Disposition: form-data; name=\"Filedata\"; filename=\"1234a.jpg\"");
sb.AppendLine("Content-Type: application/octet-stream");
sb.AppendLine("");
string postHeader = sb.ToString();
byte[] postHeaderBytes = Encoding.UTF8.GetBytes(postHeader);
//图片数据
byte[] picBytes = imageToByteArray("G:\\tmp\\1234a.jpg");
//尾部数据
string weibu = "----------cH2Ef1Ij5Ij5gL6GI3ei4Ij5Ef1gL6\r\nform-data; name=\"Upload\"\r\n\r\n5\r\n------------cH2Ef1Ij5Ij5gL6GI3ei4Ij5Ef1gL6--";
byte[] boundaryBytes = Encoding.ASCII.GetBytes(weibu);
//postdatebyte
byte[] all = new byte[postHeader.Length + picBytes.Length + boundaryBytes.Length];
postHeaderBytes.CopyTo(all, 0);
picBytes.CopyTo(all, postHeaderBytes.Length);
boundaryBytes.CopyTo(all, postHeader.Length + picBytes.Length);
//上传图片
HttpItem itemBSpic = new HttpItem()
{
URL = "http://www.tx8.cn/upload_flash.asp?id=12&sort_id=-1&rename=2&override=1 ",
Method = "post",
CookieCollection = cc,
ContentType = "multipart/form-data; boundary=" + boundary,
PostDataType = PostDataType.Byte,
PostdataByte = all,
ResultCookieType = ResultCookieType.CookieCollection
};
HttpHelper helperBSpic = new HttpHelper();
HttpResult resultBSpic = helperBSpic.GetHtml(itemBSpic);
html = resultBSpic.Html;
MessageBox.Show(html);
#endregion
//------------------------------------------------抓包信息,中间字节流乱码省略
POST http://www.tx8.cn/upload_flash.asp?id=12&sort_id=-1&rename=2&override=1 HTTP/1.1
Accept: text/*
Content-Type: multipart/form-data; boundary=----------cH2Ef1Ij5Ij5gL6GI3ei4Ij5Ef1gL6
User-Agent: Shockwave Flash
Host: www.tx8.cn
Content-Length: 26504
DNT: 1
Connection: Keep-Alive
Pragma: no-cache
Cookie: ASPSESSIONIDSADQBCQR=JGLJNBMCONNKNGOKGBOFDEEN; username=
------------cH2Ef1Ij5Ij5gL6GI3ei4Ij5Ef1gL6
Content-Disposition: form-data; name="Filename"
1234.jpg
------------cH2Ef1Ij5Ij5gL6GI3ei4Ij5Ef1gL6
Content-Disposition: form-data; name="Filedata"; filename="1234.jpg"
Content-Type: application/octet-stream
//乱码区
------------cH2Ef1Ij5Ij5gL6GI3ei4Ij5Ef1gL6
Content-Disposition: form-data; name="Upload"
Submit Query
------------cH2Ef1Ij5Ij5gL6GI3ei4Ij5Ef1gL6--
|
|