HttpPost Class |
This class allows you to post data to a server without user interaction.
The data is posted as if it were being sent from an HTML Form, allowing any form handling component to be used on the server.
Namespace: Atalasoft.Imaging
The HttpPost type exposes the following members.
Name | Description | |
---|---|---|
HttpPost | Creates a new instance of HttpPost. | |
HttpPost(ImageEncoder) | Creates a new instance of HttpPost specifying the ImageEncoder to use. | |
HttpPost(ImageEncoder, Boolean) | Creates a new instance of HttpPost specifying the ImageEncoder to use and whether or not to
combine multiple images into one post. |
Name | Description | |
---|---|---|
CombineImages | Sets or gets whether or not multiple images will be combined into one post. | |
FormData | Gets the FormDataCollection object that will be posted to the server. | |
SessionCookies |
Gets or sets the session cookies.
| |
Timeout |
Gets or sets the timeout.
|
Name | Description | |
---|---|---|
Equals | Determines whether the specified object is equal to the current object. (Inherited from Object.) | |
Finalize | Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from Object.) | |
GetData | This method can be used to retrieve information from a server. | |
GetHashCode | Serves as the default hash function. (Inherited from Object.) | |
GetType | Gets the Type of the current instance. (Inherited from Object.) | |
MemberwiseClone | Creates a shallow copy of the current Object. (Inherited from Object.) | |
PostData | This method will send the internal FormDataCollection entries to a server for processing. | |
ToString | Returns a string that represents the current object. (Inherited from Object.) |
// Load the image we want to upload. Bitmap bmp = new Bitmap(@"C:\myimage.jpg"); // We are going to save the image as JPEG on the server. HttpPost post = new HttpPost(System.Drawing.Imaging.ImageFormat.Jpeg); post.FormData.Add("image1", bmp, "myimage.jpg"); // Now lets add the additional information set by the client. post.FormData.Add("comment", this.textComment.Text); post.FormData.Add("author", this.textAuthor.Text); // Upload the image and check the return value to see if it worked. string retVal = post.PostData("http://www.mysite.com/handleupload.aspx"); if (retVal != "Success") MessageBox.Show(this, retVal, "Upload Error"); // Free the image. bmp.Dispose();
' Load the image we want to upload. Dim bmp As Bitmap = New Bitmap("C:\myimage.jpg") ' We are going to save the image as JPEG on the server. Dim post As HttpPost = New HttpPost(System.Drawing.Imaging.ImageFormat.Jpeg) post.FormData.Add("image1", bmp, "myimage.jpg") ' Now lets add the additional information set by the client. post.FormData.Add("comment", Me.textComment.Text) post.FormData.Add("author", Me.textAuthor.Text) ' Upload the image and check the return value to see if it worked. Dim retVal As String = post.PostData("http://www.mysite.com/handleupload.aspx") If retVal <> "Success" Then MessageBox.Show(this, retVal, "Upload Error") End If ' Free the image. bmp.Dispose()
This example will show you how to acquire an image from a web page and post it to the server.
<!-- The main Acquisition object. --> <object id="Twain" height="1" width="1" classid="Atalasoft.Imaging.dll#Atalasoft.Imaging.Acquisition" VIEWASTEXT> </object> <!-- Create an instance of the HttpPost object --> <object id="PostIt" height="1" width="1" classid="Atalasoft.Imaging.dll#Atalasoft.Imaging.HttpPost" VIEWASTEXT> </object> ... <script type="text/javascript"> var count = 0; function AcquireImage() { // Acquire the image. var img = document.Twain.AcquireModal(false); if (img == null) { alert('Image was not acquired.'); return; } // Send the image to the server. count++; var filename = 'image' + count + '.png'; document.PostIt.FormData.AddFromBrowser('postImage', img, filename); var response = ""; response = document.PostIt.PostData('http://localhost/TwainDemo/savepost.aspx'); // Free the form data. document.PostIt.FormData.Clear(); // Update the image. if (response.length > 0) { var el = document.getElementById('preview'); el.src = response; } else { alert("PostDataFromBrowser failed"); } } </script>