Breyta

Deila með


WebClient.UploadString Method

Definition

Uploads the specified string to the specified resource.

Overloads

UploadString(String, String)

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

UploadString(Uri, String)

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

UploadString(String, String, String)

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

UploadString(Uri, String, String)

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

UploadString(String, String)

Source:
WebClient.cs
Source:
WebClient.cs
Source:
WebClient.cs

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

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

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);
    // Display 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

Caution

WebRequest, HttpWebRequest, ServicePoint, and WebClient are obsolete, and you shouldn't use them for new development. Use HttpClient instead.

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 .NET Framework.

Applies to

UploadString(Uri, String)

Source:
WebClient.cs
Source:
WebClient.cs
Source:
WebClient.cs

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

public:
 System::String ^ UploadString(Uri ^ address, System::String ^ data);
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

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

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

Caution

WebRequest, HttpWebRequest, ServicePoint, and WebClient are obsolete, and you shouldn't use them for new development. Use HttpClient instead.

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 .NET Framework.

Applies to

UploadString(String, String, String)

Source:
WebClient.cs
Source:
WebClient.cs
Source:
WebClient.cs

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);
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

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

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

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

Caution

WebRequest, HttpWebRequest, ServicePoint, and WebClient are obsolete, and you shouldn't use them for new development. Use HttpClient instead.

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 .NET Framework.

Applies to

UploadString(Uri, String, String)

Source:
WebClient.cs
Source:
WebClient.cs
Source:
WebClient.cs

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);
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

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

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

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

Caution

WebRequest, HttpWebRequest, ServicePoint, and WebClient are obsolete, and you shouldn't use them for new development. Use HttpClient instead.

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 .NET Framework.

Applies to