c# - How upload image to server with multipart form data -
i want emulate request
this logs sniffer
-----------------------------708299735697 content-disposition: form-data; name="_file" 1.jpg -----------------------------708299735697 content-disposition: form-data; name="file"; filename="blob" content-type: image/png ‰png ............
that code on 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(); }
but code sent headers without file(1.jpg)
-----------------635031060420469298 content-disposition: form-data; name="_file" 1.jpg --------------------------635031060420469298 content-disposition: form-data; name="file"; filename="blob" content-type: image/png
i don't see anywhere reading bytes of 1.jpg file , writing request stream.
Comments
Post a Comment