我想效仿这个请求
这是来自嗅探器的日志
-----------------------------708299735697
Content-Disposition: form-data; name="_file"
1.jpg
-----------------------------708299735697
Content-Disposition: form-data; name="file"; filename="blob"
Content-Type: image/png
‰PNG
............
那是我在 csharp 上的代码。
var taimalda = DateTime.Now.Ticks;
var boundary = "------------------------" + taimalda ;
var newLine = Environment.NewLine;
var propFormat = "--" + boundary + newLine +
"Content-Disposition: form-data; name=\"{0}\"" + newLine + newLine +
"{1}" + newLine;
var fileHeaderFormat = "--" + boundary + newLine +
"Content-Disposition: form-data; name=\"{0}\"; filename=\"{1}\"" +
newLine + "Content-Type: image/png";
var req = (HttpWebRequest)HttpWebRequest.Create("http://xxx.ru/new_style/flash_uploader/upload.php?fileapi"+taimalda);
req.CookieContainer = s; //
System.Net.ServicePointManager.Expect100Continue = false;
req.Referer = "http://www.xxx.ru/user/setting/set_info"; // add referer
req.UserAgent = "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:2.0) Gecko/20100101 Firefox/4.0"; // add useragent
req.Method = WebRequestMethods.Http.Post; // post request
req.ContentType = "multipart/form-data; boundary=" + boundary;
using (var reqStream = req.GetRequestStream())
{
var reqWriter = new StreamWriter(reqStream);
var tmp = string.Format(propFormat, "_file", "1.jpg");
reqWriter.Write(tmp);
tmp = string.Format(fileHeaderFormat, "file", "blob");
reqWriter.Write(tmp);
reqWriter.Flush();
}
var res = req.GetResponse();
using (var resStream = res.GetResponseStream())
{
var reader = new StreamReader(resStream);
var ext = reader.ReadToEnd();
}
但是这段代码只发送了没有我的文件的标题(1.jpg)
-----------------635031060420469298 内容处置:表单数据;名称="_file" 1.jpg --------------------------635031060420469298 内容处置:表单数据;名称=“文件”;文件名=“blob” 内容类型:图片/png