Click to Rate and Give Feedback
MSDN
MSDN Library
Web Development
Silverlight 3
 Method Property

  Switch on low bandwidth view
.NET Framework Class Library for Silverlight
HttpWebRequest..::.Method Property

Gets or sets the method for the request.

Namespace:  System.Net
Assembly:  System.Net (in System.Net.dll)
Visual Basic (Declaration)
Public Overrides Property Method As String
    Get
    Set
Visual Basic (Usage)
Dim instance As HttpWebRequest
Dim value As String

value = instance.Method

instance.Method = value
C#
public override string Method { get; set; }

Property Value

Type: System..::.String
The request method to use to contact the Internet resource. The default value is GET.
ExceptionCondition
ArgumentException

No method is supplied.

-or-

The method string contains invalid characters.

NotImplementedException

This property is not implemented.

NotSupportedException

The Method property is not GET or POST.

The Method property can only be set to GET and POST methods. Any other HTTP 1.1 or 1.0 protocol verbs (HEAD, PUT, DELETE, TRACE, or OPTIONS, for example) will throw a NotSupportedException exception.

If an application implements a custom WebRequest class and does not override the Method property, then the NotImplementedException is thrown.

Visual Basic
' Change this Uri to a public server
Dim myUri As System.Uri = New Uri("http://www.contoso.com")

' Create a 'HttpWebRequest' object.
Dim myHttpWebRequest As HttpWebRequest = WebRequest.Create(myUri)

' Set the 'Method' property to "POST".
myHttpWebRequest.Method="PUT"

' Set the 'ContentType' property.
myHttpWebRequest.ContentType="application/x-www-form-urlencoded"

' Get the 'ContentType' property and print the current value
outputBlock.Text &= "HttpWebRequest.ContentType: "
outputBlock.Text &= myHttpWebRequest.ContentType
outputBlock.Text &= vbCrLf

C#
        // Change this Uri to a public server
        System.Uri myUri = new Uri("http://www.contoso.com");

        // Create a 'HttpWebRequest' object.
        HttpWebRequest myHttpWebRequest=(HttpWebRequest)WebRequest.Create(myUri);

        // Set the 'Method' property to "POST".
        myHttpWebRequest.Method="PUT";

        // Set the 'ContentType' property.
        myHttpWebRequest.ContentType="application/x-www-form-urlencoded";

        // Get the 'ContentType' property and print the current value
        outputBlock.Text += "HttpWebRequest.ContentType: ";
        outputBlock.Text += myHttpWebRequest.ContentType;
        outputBlock.Text += "\n";


For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.

Tags What's this?: Add a tag
Community Content   What is Community Content?
Add new content RSS  Annotations
Processing
© 2009 Microsoft Corporation. All rights reserved. Terms of Use  |  Trademarks  |  Privacy Statement
Page view tracker