Method Property

HttpWebRequest.Method Property


Gets or sets the method for the request.

Namespace:   System.Net
Assembly:  System (in System.dll)

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.

Exception Condition

No method is supplied.


The method string contains invalid characters.

The Method property can be set to any of the HTTP 1.1 protocol verbs: GET, HEAD, POST, PUT, DELETE, TRACE, or OPTIONS.

If the ContentLength property is set to any value other than -1, the Method property must be set to a protocol property that uploads data.

The following code example sets the Method property to POST.

Snippet section 4 of code snippet {"project_id":"3fedad16-eaf1-41a6-8f96-0c1949c68f32","entity_id":"c6311be3-35b7-428b-9cd3-f2e7bd4bc5aa","entity_type":"CodeSnippet","locale":"en-US"} in source file ({"filename":"/CS/httpwebrequest_contentlength.cs","blob_type":"Source","blob_id":"-002fcs-002fhttpwebrequest-005fcontentlength-002ecs","blob_revision":3}) overlaps with other snippet sections. Ensure the tags are placed correctly.

Universal Windows Platform
Available since 4.5
.NET Framework
Available since 1.1
Portable Class Library
Supported in: portable .NET platforms
Available since 2.0
Windows Phone Silverlight
Available since 7.0
Windows Phone
Available since 8.1
Return to top
© 2015 Microsoft