winforms - Multipart/Form-Data post in WebBrowser C# -


i need send post file webbrowser control...

html page form:

<form enctype="multipart/form-data" action="http://localhost:8987/up.php" method="post"> <input type="hidden" name="max_file_size" value="100000" /> <input type="hidden" name="vl1" value="k1" /> <input type="hidden" name="vl2" value="k2" /> <input type="hidden" name="vl3" value="k3" /> choose file upload: <input name="filedata" type="file" /><br /> <input type="submit" value="upload file" /> </form> 

here how try send post webbrowser.

string datacontent = "-----------------------------2206917386657\\r\\ncontent-disposition: form-data; name=\"filedata\"; filename=\"joey.php\"\\r\\ncontent-type: application/octet-stream\\r\\n\\r\\ncontent_of_file\\r\\n\\r\\n-----------------------------2206917386657\\r\\ncontent-disposition: form-data; name=\"return-url\"\\r\\n\\r\\naw5kzxgucghwp29wdglvbj1jb21fbwvkawe=\\r\\n-----------------------------2206917386657--\\r\\n\\"; var datapost = encoding.utf8.getbytes(datacontent); webbrowser1.navigate(urlpost2, null, datapost, "content-type: multipart/form-data;" + environment.newline); 

but when send post recieved message:

please input file upload

is datapost dont work...

anyone have 1 idea me??

thanks!! (sry bad english, i'm brazilian guy)


--edit: found solution:

string boundary = "---------------------------0123456789012";                         string d;                         d = "--" + boundary + environment.newline;                         d = d + "content-disposition: form-data; name=\"filedata\";";                         d = d + "filename=\"joey.php\"" + environment.newline;                         d = d + "content-type: application/upload" + environment.newline + environment.newline;                         d = d + "(content)";                         d = d + environment.newline + "--" + boundary + "--" + environment.newline;                         var datapost2 = encoding.utf8.getbytes(d);                         webbrowser1.navigate(urlpost, null, datapost2, "content-type: multipart/form-data; boundary=" + boundary + environment.newline); 

work 100%!!!!!


Comments