开发者

C# upload file to website

I am attempting to post a reply to an image board website. It can be done through a winfor开发者_Go百科m web browser control or http request. The issue is that with a post, you can upload an image with a input type file element on the page

<input type="file" />

For security reasons, I cannot set the value of the element to the file I want to upload.

When I use tamper data to see what is passed to the posting page, this is parameter that is passed under POST_DATA

-----------------------------256672629917035
Content-Disposition: form-data; name="upfile"; filename="image_file_name.jpg"
Content-Type: image/jpeg

So how is it possible to simulate a file upload of a input element in C#?

Look closely at the data that was posted, no directory is specified.


You can simulate any HTTP request through the HttpWebRequest object. Click here for an example.

When you're using the input type file element the browser is creating the request this for you. If you simply recreate this in HttpWebRequest you have full control over all aspects of the request and can modifiy as you wish.

It's probably in your interest to grab a copy of Fiddler.


If I understood your problem right, you can't determine the directory of the file which was uploaded from your web browser control.

So ... it is impossible. The information about directory isn't given by browser - so it shouldn't be given by web browser control.

As MizardX suggested, it's better to send request using C#.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜