473,671 Members | 2,252 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_fo rm"
enctype="multip art/form-data" method="POST">

2 ) My vb.net code for POST request:
Dim lcUrl As String = "http://abc.com/save_photos.php "
Dim myHttpWebReques t As HttpWebRequest =
DirectCast(WebR equest.Create(l cUrl), HttpWebRequest)
myHttpWebReques t.Method = "POST"

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

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

' Set the content type of the data being posted.
myHttpWebReques t.ContentType = "applicatio n/x-www-form-urlencoded"

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

Hope you can help.

Thanks,
Jason
Nov 21 '05 #1
1 14390
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*******@sina man.com> ¼¶¼g©ó¶l¥ó·s»D: %2************* *****@TK2MSFTNG P09.phx.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_fo rm"
enctype="multip art/form-data" method="POST">

2 ) My vb.net code for POST request:
Dim lcUrl As String = "http://abc.com/save_photos.php "
Dim myHttpWebReques t As HttpWebRequest =
DirectCast(WebR equest.Create(l cUrl), HttpWebRequest)
myHttpWebReques t.Method = "POST"

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

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

' Set the content type of the data being posted.
myHttpWebReques t.ContentType = "applicatio n/x-www-form-urlencoded"

'Do I need to set cotnet type as below if transfer data file?
'myHttpWebReque st.ContentType = "multipart/form-data encode"
' Set the content length of the string being posted.
myHttpWebReques t.ContentLength = postData.Length
Dim newStream As Stream = myHttpWebReques t.GetRequestStr eam()
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
4441
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 part, the scripts were created with http://phpcodegenie.sourceforge.net/
24
2728
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 NAME="InputForm" ACTION="UploadAction.jsp" METHOD="POST" enctype=multipart/form-data> <input type="file" name="fileName"> //etc ...
4
14821
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 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
2
1724
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 System.Web.HttpUtility.UploadFile() Neither provide seperation boundaries and that seems to fail the operation. I am using "POST" for the method type.
3
23065
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 allowed to upload files. Checks should be made to make sure that only allowed file types are uploaded. The Client-Side First of all, let us deal with the client side. This assumes some knowledge of HTML.
1
2049
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 time. Drew
2
6300
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 enctype="multipart/form-data" method="post" name="testform">
0
1395
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 resolution.... I have tried the printform comp with pdf creator but when i zoom it in to display the whole form on screen and then print it, the pdf created isn't proper as in when i zoom it in the text and stuff isn't readable... when i don't zoom...
5
3103
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 following script but it doesn't work, <?php $uploaddir = '/var/www/vhosts/nitinsawant.com/subdomains/httpdocs/files/'; $uploadfile = $uploaddir . basename($_FILES);
0
8476
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8393
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
7437
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6229
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4225
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4407
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2812
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 we have to send another system
2
2051
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1809
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.