Send file to server by HTTP-Post method

E

Evgeny Zoldin

Hi ALL.

I would like to download file from some web-server that requires
Basic-Authetication, change somthing in the file and upload it back to the
server.
I can download the file and proceed as I need, but how should I upload it
back? Server provides standard HTML GUI for Browsers where client can fill
appropriate input field of the form with a full name of the local file. The
form uses POST method to upload file and has attribute

enctype="multipart/form-data"

What the simplest way to upload file programmatically? Is it possible to
control the uploading process if any?

Thanx
Evgeny
 
R

Richard Bower

Save posted file:
C#
((HttpPostedFile)HttpContext.Current.Request.Files[<filename>]).SaveAs(
<savetolocation> ) ;
 
S

Scott Allen

I have an article with some tips on using WebClient and WebRequest to
post data, though it doesn't deal with file upload specifically:
http://odetocode.com/Articles/162.aspx

The article references a tool "Fiddler", which is an Http Debugging
Proxy and a great way to see "how your browser does it".

HTH,
 
J

Jerry Pisk

I think you're asking whether you can automatically upload a file, without
the user interaction. The short answer is no, you can't. It would be a huge
security hole into the system. You will have to install an ActiveX control
(and be careful, .Net user controls will not help you here as they are
hosted in a secure environment) that would read the file and upload it. But
then again, unless you do it really well (as in only upload to a known host
name, over SSL) you will open a security hole into whoever installs the
control.

Jerry
 
J

Joerg Jooss

Evgeny said:
Hi ALL.

I would like to download file from some web-server that requires
Basic-Authetication, change somthing in the file and upload it back
to the server.
I can download the file and proceed as I need, but how should I
upload it back? Server provides standard HTML GUI for Browsers where
client can fill appropriate input field of the form with a full name
of the local file. The form uses POST method to upload file and has
attribute

enctype="multipart/form-data"

What the simplest way to upload file programmatically? Is it possible
to control the uploading process if any?

There's no "simple way" -- what you want is a proper implementation of
http://www.faqs.org/rfcs/rfc2388.html, based on
HttpWebRequest/HttpWebResponse. WebClient.UploadFile() should have been
that, but has a bug that may cause some server-side upload facilities (like
PHP) to fail.

Cheers,
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top