Click or drag to resize

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.

Inheritance Hierarchy
SystemObject
  Atalasoft.ImagingHttpPost

Namespace:  Atalasoft.Imaging
Assembly:  Atalasoft.dotImage (in Atalasoft.dotImage.dll) Version: 11.4.0.9.0.377 (.NET 4.5.2, x86)
Syntax
public class HttpPost

The HttpPost type exposes the following members.

Constructors
  NameDescription
Public methodHttpPost
Creates a new instance of HttpPost.
Public methodHttpPost(ImageEncoder)
Creates a new instance of HttpPost specifying the ImageEncoder to use.
Public methodHttpPost(ImageEncoder, Boolean)
Creates a new instance of HttpPost specifying the ImageEncoder to use and whether or not to combine multiple images into one post.
Top
Properties
  NameDescription
Public propertyCombineImages
Sets or gets whether or not multiple images will be combined into one post.
Public propertyFormData
Gets the FormDataCollection object that will be posted to the server.
Public propertySessionCookies
Gets or sets the session cookies.
Public propertyTimeout
Gets or sets the timeout.
Top
Methods
  NameDescription
Public methodEquals
Determines whether the specified object is equal to the current object.
(Inherited from Object.)
Protected methodFinalize
Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection.
(Inherited from Object.)
Public methodGetData
This method can be used to retrieve information from a server.
Public methodGetHashCode
Serves as the default hash function.
(Inherited from Object.)
Public methodGetType
Gets the Type of the current instance.
(Inherited from Object.)
Protected methodMemberwiseClone
Creates a shallow copy of the current Object.
(Inherited from Object.)
Public methodPostData
This method will send the internal FormDataCollection entries to a server for processing.
Public methodToString
Returns a string that represents the current object.
(Inherited from Object.)
Top
Examples
Posting an image (C#)
// 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();
Posting an image (Visual Basic)
' 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.

Posting from a browser (JScript)
<!-- 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>
See Also