473,513 Members | 2,605 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Windows Form upload data file by HTTP POST

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 below. But I don't know how to encode
the data file so the server can be recognized.

1 ) Traditional HTML code for upload a file:
<form action="http://abc.com/save_photos.php" name="upload_form"
enctype="multipart/form-data" method="POST">

2 ) My vb.net code for POST request:
Dim lcUrl As String = "http://abc.com/save_photos.php"
Dim myHttpWebRequest As HttpWebRequest =
DirectCast(WebRequest.Create(lcUrl), HttpWebRequest)
myHttpWebRequest.Method = "POST"

' Create a new string object to POST data to the Url.
Dim inputData As String = "cmd=" & HttpUtility.UrlEncode("login")

Dim postData As String = inputData
Dim encoding As New ASCIIEncoding
Dim byte1 As Byte() = encoding.GetBytes(postData)

' Set the content type of the data being posted.
myHttpWebRequest.ContentType = "application/x-www-form-urlencoded"

'Do I need to set cotnet type as below if transfer data file?
'myHttpWebRequest.ContentType = "multipart/form-data encode"
' Set the content length of the string being posted.
myHttpWebRequest.ContentLength = postData.Length
Dim newStream As Stream = myHttpWebRequest.GetRequestStream()
newStream.Write(byte1, 0, byte1.Length)
newStream.Close()

Hope you can help.

Thanks,
Jason
Nov 21 '05 #1
1 14286
Hi,

I found the solution by myself. If you are interested, pls have a look at:

http://www.codeproject.com/csharp/UploadFileEx.asp

Jason

"Jason Ho" <fa*******@sinaman.com> ¼¶¼g©ó¶l¥ó·s»D:%2******************@TK2MSFTNGP09.p hx.gbl...
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 below. But I don't know how to
encode the data file so the server can be recognized.

1 ) Traditional HTML code for upload a file:
<form action="http://abc.com/save_photos.php" name="upload_form"
enctype="multipart/form-data" method="POST">

2 ) My vb.net code for POST request:
Dim lcUrl As String = "http://abc.com/save_photos.php"
Dim myHttpWebRequest As HttpWebRequest =
DirectCast(WebRequest.Create(lcUrl), HttpWebRequest)
myHttpWebRequest.Method = "POST"

' Create a new string object to POST data to the Url.
Dim inputData As String = "cmd=" & HttpUtility.UrlEncode("login")

Dim postData As String = inputData
Dim encoding As New ASCIIEncoding
Dim byte1 As Byte() = encoding.GetBytes(postData)

' Set the content type of the data being posted.
myHttpWebRequest.ContentType = "application/x-www-form-urlencoded"

'Do I need to set cotnet type as below if transfer data file?
'myHttpWebRequest.ContentType = "multipart/form-data encode"
' Set the content length of the string being posted.
myHttpWebRequest.ContentLength = postData.Length
Dim newStream As Stream = myHttpWebRequest.GetRequestStream()
newStream.Write(byte1, 0, byte1.Length)
newStream.Close()

Hope you can help.

Thanks,
Jason

Nov 21 '05 #2

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

Similar topics

4
4415
by: Nomen Nescio | last post by:
can anyone be so kind as to look at http://www.mysolution.ws/HYPOCRITE.php and let me know why it isn't passing the form data to http://www.mysolution.ws/insertHYPOCRITES.php for the most...
24
2711
by: jrefactors | last post by:
I have an upload file operation in the web application. UploadForm.jsp is the form, and UploadAction.jsp is the form processing. The web server is Websphere. //UploadForm.jsp <FORM...
4
14794
by: Evgeny Zoldin | last post by:
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...
2
1713
by: Brett | last post by:
Does any one have examples of how to upload a file via POST and also include other form fields? Say two input boxes and a file type input. I've tried: WebRequest.Create() and...
3
23033
acoder
by: acoder | last post by:
How to Upload a File in Coldfusion Use the cffile tag for uploading files to the server. Note that allowing people to upload files is fraught with danger and only trusted users should be...
1
2041
by: whitfieldd | last post by:
I am fairly new to the python language. I need to retieve data (XML file data) from http post using python. Are there any libraries that can point me in the right direction? Thanks for your...
2
6275
by: MDANH2002 | last post by:
Hi From VB.NET I want to simulate the POST request of the following HTML form <html> <title>HTTP Post Testing</title> <body> <form action=http://www.example.com/postdata ...
0
1386
by: SidraHaque | last post by:
Hi, I have made a form that is really big ... its almost 5000 by 4000 ... and its got buttons pannels labels ... Now i need to convert this whole form into pdf file in a way that it doen't lose its...
5
3091
by: NitinSawant | last post by:
Hello, I'm beginner to php (actually i'm java/jsp developer), What i'm trying to do is Accept parameters from the HTML file and write them to a newly created file using php, I wrote...
0
7260
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7160
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
7525
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...
1
5086
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...
0
4746
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3233
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3222
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1594
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
799
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.