0
我想效仿這一要求如何上傳圖片與多形式的數據服務器
這是從嗅探
-----------------------------708299735697
Content-Disposition: form-data; name="_file"
1.jpg
-----------------------------708299735697
Content-Disposition: form-data; name="file"; filename="blob"
Content-Type: image/png
‰PNG
............
這是我的IE編程代碼日誌。
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 Content-Disposition: form-data; name="_file" 1.jpg --------------------------635031060420469298 Content-Disposition: form-data; name="file"; filename="blob" Content-Type: image/png
我不能轉換的字節數組字符數組 – user1088259 2013-05-02 17:51:32