473,412 Members | 1,873 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,412 software developers and data experts.

How to upload file via HttpWebRequest POST?

I'd like to upload a file in vb.net vis POST using HttpWebRequest. It needs
to simulate some one using a webform. The webform works fine when I
manually upload through the web browser. However, this code will return an
error 500 on the line indicated below. I'm passing the upload file field
name and value basically through a URL. Any suggested how I can get this
file to upload?

Dim MainForm As New InterfaceMain
Dim strResult As String = ""
Dim strPost As String = "method=upLoadList"
strPost = strPost & "&FileToUpload=c:\mytextfile.txt"

Dim objRequest As HttpWebRequest =
WebRequest.Create("http://www.somesite.com")
Dim myWriter As StreamWriter

objRequest.Method = "POST"
objRequest.ContentLength = strPost.Length
objRequest.ContentType = "multipart/form-data"

Try
myWriter = New StreamWriter(objRequest.GetRequestStream())
myWriter.Write(strPost)
Catch ex As Exception
MsgBox(ex.Message())
Finally
myWriter.Close()
End Try

Try

Dim objResponse As System.Net.HttpWebResponse =
objRequest.GetResponse 'Internal error 500 occurs here
Dim sr As New System.IO.StreamReader(objResponse.GetResponseStre am)
Dim result As String = sr.ReadToEnd
sr.Close()

I've also tried appended "?" to the URL
http://www.somesite.com?
but that doesn't work either.

Thanks,
Brett
Nov 21 '05 #1
0 7953

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: R Reyes | last post by:
I am trying to code a file uploader (for forum/email attachments) from the client computer to a remote web server via the PUT method (since POST is not allowed ). However, the upload works ONLY...
5
by: John Lee | last post by:
Hi, I have a simple web page that allow file to be uploaded, the upload page looks like the following: <form method="post" name="upload" enctype="multipart/form-data"...
2
by: Jonathan Wax | last post by:
Hi, I spent the last week looking for an answer to the following question: How can you upload an xml file to an HTTPS server with a specific certificate. Basically doing the same as this html...
1
by: Jason Ho | last post by:
Hi, I would like to send a jpg file to a HTTP server by POST request. But I am not using a browser to do this, I use a Windows Form instead. I know how to send typical request by POST with code...
7
by: russell.lane | last post by:
I've been looking at both MTOM and simple HTTP POST or PUT for file uploads. Some relevant details: ... We want to support programmatic file uploads from Winform apps. ... The files are large...
0
by: tom | last post by:
What I want to do is upload a zip file to an https website. The site itself uses secure File transport. Now webclient has the simplicity to upload a file, but I cannot attach the neccessary cert to...
4
by: Spam Catcher | last post by:
Anyone know of any form upload utilities which will allow me to upload files to an ASP.NET page without the need of a web browser? I like to test a form upload page I wrote (no GUI, it only...
1
by: Gert Conradie | last post by:
The following code can uplaod text files. When i upload a binary file it fail. I might be: 1) using the wrong Encoding 2) will have to System.Convert.ToBase64String the content of the binary...
5
by: kamlesh20J | last post by:
Hello, I am trying to use HttpWebRequest to send some POST data I have accomplished this using: HttpWebRequest req = (HttpWebRequest) WebRequest.Create("http://mysite.com/index.php");...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.