WebClient.UploadString WebClient.UploadString WebClient.UploadString WebClient.UploadString Method

Definition

Uploads the specified string to the specified resource.

Overloads

UploadString(String, String) UploadString(String, String) UploadString(String, String) UploadString(String, String)

Uploads the specified string to the specified resource, using the POST method.

UploadString(Uri, String) UploadString(Uri, String) UploadString(Uri, String) UploadString(Uri, String)

Uploads the specified string to the specified resource, using the POST method.

UploadString(String, String, String) UploadString(String, String, String) UploadString(String, String, String) UploadString(String, String, String)

Uploads the specified string to the specified resource, using the specified method.

UploadString(Uri, String, String) UploadString(Uri, String, String) UploadString(Uri, String, String) UploadString(Uri, String, String)

Uploads the specified string to the specified resource, using the specified method.

UploadString(String, String) UploadString(String, String) UploadString(String, String) UploadString(String, String)

Uploads the specified string to the specified resource, using the POST method.

public:
 System::String ^ UploadString(System::String ^ address, System::String ^ data);
public string UploadString (string address, string data);
member this.UploadString : string * string -> string
Public Function UploadString (address As String, data As String) As String
Parameters
address
String String String String

The URI of the resource to receive the string. For Http resources, this URI must identify a resource that can accept a request sent with the POST method, such as a script or ASP page.

data
String String String String

The string to be uploaded.

Returns

A String containing the response sent by the server.

Exceptions

The address parameter is null.

-or-

The data parameter is null.

The URI formed by combining BaseAddress and address is invalid.

-or-

There was no response from the server hosting the resource.

Examples

The following code example demonstrates calling this method.

void UploadString( String^ address )
{
   String^ data = "Time = 12:00am temperature = 50";
   WebClient^ client = gcnew WebClient;
   
   // Optionally specify an encoding for uploading and downloading strings.
   client->Encoding = System::Text::Encoding::UTF8;
   
   // Upload the data.
   String^ reply = client->UploadString( address, data );
   
   // Disply the server's response.
   Console::WriteLine( reply );
}


public static void UploadString (string address)
{
    string data = "Time = 12:00am temperature = 50";
    WebClient client = new WebClient ();
    // Optionally specify an encoding for uploading and downloading strings.
    client.Encoding = System.Text.Encoding.UTF8;
    // Upload the data.
    string reply = client.UploadString (address, data);
    // Disply the server's response.
    Console.WriteLine (reply);
}

Public Shared Sub UploadString(ByVal address As String)

	Dim data As String = "Time = 12:00am temperature = 50"
	Dim client As WebClient = New WebClient()
	'  Optionally specify an encoding for uploading and downloading strings.
	client.Encoding = System.Text.Encoding.UTF8
	'  Upload the data.
	Dim reply As String = client.UploadString(address, data)
	'  Disply the server's response.
	Console.WriteLine(reply)
End Sub

Remarks

Before uploading the string, this method converts it to a Byte array using the encoding specified in the Encoding property. This method blocks while the string is transmitted. To send a string and continue executing while waiting for the server's response, use one of the UploadStringAsync methods.

If the BaseAddress property is not an empty string (""), and address does not contain an absolute URI, address must be a relative URI that is combined with BaseAddress to form the absolute URI of the requested data. If the QueryString property is not an empty string, it is appended to address.

This method uses the STOR command to upload an FTP resource. For an HTTP resource, the POST method is used.

Note

This member outputs trace information when you enable network tracing in your application. For more information, see Network Tracing in the .NET Framework.

UploadString(Uri, String) UploadString(Uri, String) UploadString(Uri, String) UploadString(Uri, String)

Uploads the specified string to the specified resource, using the POST method.

public:
 System::String ^ UploadString(Uri ^ address, System::String ^ data);
[System.Runtime.TargetedPatchingOptOut("Performance critical to inline this type of method across NGen image boundaries")]
public string UploadString (Uri address, string data);
member this.UploadString : Uri * string -> string
Public Function UploadString (address As Uri, data As String) As String
Parameters
address
Uri Uri Uri Uri

The URI of the resource to receive the string. For Http resources, this URI must identify a resource that can accept a request sent with the POST method, such as a script or ASP page.

data
String String String String

The string to be uploaded.

Returns

A String containing the response sent by the server.

Exceptions

The address parameter is null.

-or-

The data parameter is null.

The URI formed by combining BaseAddress and address is invalid.

-or-

There was no response from the server hosting the resource.

Remarks

Before uploading the string, this method converts it to a Byte array using the encoding specified in the Encoding property. This method blocks while the string is transmitted. To send a string and continue executing while waiting for the server's response, use one of the UploadStringAsync methods.

If the BaseAddress property is not an empty string (""), and address does not contain an absolute URI, address must be a relative URI that is combined with BaseAddress to form the absolute URI of the requested data. If the QueryString property is not an empty string, it is appended to address.

This method uses the STOR command to upload an FTP resource. For an HTTP resource, the POST method is used.

Note

This member outputs trace information when you enable network tracing in your application. For more information, see Network Tracing in the .NET Framework.

UploadString(String, String, String) UploadString(String, String, String) UploadString(String, String, String) UploadString(String, String, String)

Uploads the specified string to the specified resource, using the specified method.

public:
 System::String ^ UploadString(System::String ^ address, System::String ^ method, System::String ^ data);
public string UploadString (string address, string method, string data);
member this.UploadString : string * string * string -> string
Public Function UploadString (address As String, method As String, data As String) As String
Parameters
address
String String String String

The URI of the resource to receive the string. This URI must identify a resource that can accept a request sent with the method method.

method
String String String String

The HTTP method used to send the string to the resource. If null, the default is POST for http and STOR for ftp.

data
String String String String

The string to be uploaded.

Returns

A String containing the response sent by the server.

Exceptions

The address parameter is null.

-or-

The data parameter is null.

The URI formed by combining BaseAddress and address is invalid.

-or-

There was no response from the server hosting the resource.

-or-

method cannot be used to send content.

Examples

The following code example demonstrates calling this method.

void PostString( String^ address )
{
   String^ data = "Time = 12:00am temperature = 50";
   String^ method = "POST";
   WebClient^ client = gcnew WebClient;
   String^ reply = client->UploadString( address, method, data );
   Console::WriteLine( reply );
}


public static void PostString (string address)
{
    string data = "Time = 12:00am temperature = 50";
    string method = "POST";
    WebClient client = new WebClient ();
    string reply = client.UploadString (address, method, data);

    Console.WriteLine (reply);
}

Public Shared Sub PostString(ByVal address As String)

	Dim data As String = "Time = 12:00am temperature = 50"
	Dim method As String = "POST"
	Dim client As WebClient = New WebClient()
	Dim reply As String = client.UploadString(address, method, data)

	Console.WriteLine(reply)
End Sub

Remarks

Before uploading the string, this method converts it to a Byte array using the encoding specified in the Encoding property. This method blocks while the string is transmitted. To send a string and continue executing while waiting for the server's response, use one of the UploadStringAsync methods.

If the BaseAddress property is not an empty string ("") and address does not contain an absolute URI, address must be a relative URI that is combined with BaseAddress to form the absolute URI of the requested data. If the QueryString property is not an empty string, it is appended to address.

Note

This member outputs trace information when you enable network tracing in your application. For more information, see Network Tracing in the .NET Framework.

UploadString(Uri, String, String) UploadString(Uri, String, String) UploadString(Uri, String, String) UploadString(Uri, String, String)

Uploads the specified string to the specified resource, using the specified method.

public:
 System::String ^ UploadString(Uri ^ address, System::String ^ method, System::String ^ data);
public string UploadString (Uri address, string method, string data);
member this.UploadString : Uri * string * string -> string
Public Function UploadString (address As Uri, method As String, data As String) As String
Parameters
address
Uri Uri Uri Uri

The URI of the resource to receive the string. This URI must identify a resource that can accept a request sent with the method method.

method
String String String String

The HTTP method used to send the string to the resource. If null, the default is POST for http and STOR for ftp.

data
String String String String

The string to be uploaded.

Returns

A String containing the response sent by the server.

Exceptions

The address parameter is null.

-or-

The data parameter is null.

The URI formed by combining BaseAddress and address is invalid.

-or-

There was no response from the server hosting the resource.

-or-

method cannot be used to send content.

Remarks

Before uploading the string, this method converts it to a Byte array using the encoding specified in the Encoding property. This method blocks while the string is transmitted. To send a string and continue executing while waiting for the server's response, use one of the UploadStringAsync methods.

If the BaseAddress property is not an empty string ("") and address does not contain an absolute URI, address must be a relative URI that is combined with BaseAddress to form the absolute URI of the requested data. If the QueryString property is not an empty string, it is appended to address.

Note

This member outputs trace information when you enable network tracing in your application. For more information, see Network Tracing in the .NET Framework.

Applies to