WebClient.UploadString 方法
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
將指定的字串上傳至指定的資源。
多載
| UploadString(String, String) |
使用 POST 方法,將指定的字串上傳至指定的資源。 |
| UploadString(Uri, String) |
使用 POST 方法,將指定的字串上傳至指定的資源。 |
| UploadString(String, String, String) |
使用指定的 方法,將指定的字串上傳至指定的資源。 |
| UploadString(Uri, String, String) |
使用指定的 方法,將指定的字串上傳至指定的資源。 |
UploadString(String, String)
- 來源:
- WebClient.cs
- 來源:
- WebClient.cs
- 來源:
- WebClient.cs
使用 POST 方法,將指定的字串上傳至指定的資源。
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
參數
- address
- String
要接收字串之資源的 URI。 針對 Http 資源,此 URI 必須識別可接受 POST 方法所傳送要求的資源,例如腳本或 ASP 頁面。
- data
- String
要上傳的字串。
傳回
包含伺服器所傳送回應的 String。
例外狀況
範例
下列程式代碼範例示範呼叫這個方法。
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
備註
謹慎
WebRequest、HttpWebRequest、ServicePoint和 WebClient 已經過時,您不應該將它們用於新的開發。 請改用 HttpClient。
上傳字串之前,這個方法會使用 Encoding 屬性中指定的編碼,將它轉換成 Byte 陣列。 這個方法會在傳輸字串時封鎖。 若要傳送字串,並在等候伺服器的回應時繼續執行,請使用其中一個 UploadStringAsync 方法。
如果 BaseAddress 屬性不是空字串 (“”),且 address 不包含絕對 URI,address 必須是與 BaseAddress 結合的相對 URI,才能形成所要求數據的絕對 URI。 如果 QueryString 屬性不是空字串,則會附加至 address。
此方法會使用 STOR 命令來上傳 FTP 資源。 如果是 HTTP 資源,則會使用 POST 方法。
注意
當您在應用程式中啟用網路追蹤時,此成員會輸出追蹤資訊。 如需詳細資訊,請參閱 .NET Framework 中的網路追蹤。
適用於
UploadString(Uri, String)
- 來源:
- WebClient.cs
- 來源:
- WebClient.cs
- 來源:
- WebClient.cs
使用 POST 方法,將指定的字串上傳至指定的資源。
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
參數
- address
- Uri
要接收字串之資源的 URI。 針對 Http 資源,此 URI 必須識別可接受 POST 方法所傳送要求的資源,例如腳本或 ASP 頁面。
- data
- String
要上傳的字串。
傳回
包含伺服器所傳送回應的 String。
例外狀況
備註
謹慎
WebRequest、HttpWebRequest、ServicePoint和 WebClient 已經過時,您不應該將它們用於新的開發。 請改用 HttpClient。
上傳字串之前,這個方法會使用 Encoding 屬性中指定的編碼,將它轉換成 Byte 陣列。 這個方法會在傳輸字串時封鎖。 若要傳送字串,並在等候伺服器的回應時繼續執行,請使用其中一個 UploadStringAsync 方法。
如果 BaseAddress 屬性不是空字串 (“”),且 address 不包含絕對 URI,address 必須是與 BaseAddress 結合的相對 URI,才能形成所要求數據的絕對 URI。 如果 QueryString 屬性不是空字串,則會附加至 address。
此方法會使用 STOR 命令來上傳 FTP 資源。 如果是 HTTP 資源,則會使用 POST 方法。
注意
當您在應用程式中啟用網路追蹤時,此成員會輸出追蹤資訊。 如需詳細資訊,請參閱 .NET Framework 中的網路追蹤。
適用於
UploadString(String, String, String)
- 來源:
- WebClient.cs
- 來源:
- WebClient.cs
- 來源:
- WebClient.cs
使用指定的 方法,將指定的字串上傳至指定的資源。
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
參數
- address
- String
要接收字串之資源的 URI。 此 URI 必須識別可接受以 method 方法傳送之要求的資源。
- method
- String
用來將字串傳送至資源的 HTTP 方法。 如果為 null,則預設值為 HTTP 的 POST,而 FTP 則為 STOR。
- data
- String
要上傳的字串。
傳回
包含伺服器所傳送回應的 String。
例外狀況
範例
下列程式代碼範例示範呼叫這個方法。
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
備註
謹慎
WebRequest、HttpWebRequest、ServicePoint和 WebClient 已經過時,您不應該將它們用於新的開發。 請改用 HttpClient。
上傳字串之前,這個方法會使用 Encoding 屬性中指定的編碼,將它轉換成 Byte 陣列。 這個方法會在傳輸字串時封鎖。 若要傳送字串,並在等候伺服器的回應時繼續執行,請使用其中一個 UploadStringAsync 方法。
如果 BaseAddress 屬性不是空字串 (“”) 且 address 不包含絕對 URI,address 必須是與 BaseAddress 結合的相對 URI,才能形成所要求數據的絕對 URI。 如果 QueryString 屬性不是空字串,則會附加至 address。
注意
當您在應用程式中啟用網路追蹤時,此成員會輸出追蹤資訊。 如需詳細資訊,請參閱 .NET Framework 中的網路追蹤。
適用於
UploadString(Uri, String, String)
- 來源:
- WebClient.cs
- 來源:
- WebClient.cs
- 來源:
- WebClient.cs
使用指定的 方法,將指定的字串上傳至指定的資源。
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
參數
- address
- Uri
要接收字串之資源的 URI。 此 URI 必須識別可接受以 method 方法傳送之要求的資源。
- method
- String
用來將字串傳送至資源的 HTTP 方法。 如果為 null,則預設值為 HTTP 的 POST,而 FTP 則為 STOR。
- data
- String
要上傳的字串。
傳回
包含伺服器所傳送回應的 String。
例外狀況
備註
謹慎
WebRequest、HttpWebRequest、ServicePoint和 WebClient 已經過時,您不應該將它們用於新的開發。 請改用 HttpClient。
上傳字串之前,這個方法會使用 Encoding 屬性中指定的編碼,將它轉換成 Byte 陣列。 這個方法會在傳輸字串時封鎖。 若要傳送字串,並在等候伺服器的回應時繼續執行,請使用其中一個 UploadStringAsync 方法。
如果 BaseAddress 屬性不是空字串 (“”) 且 address 不包含絕對 URI,address 必須是與 BaseAddress 結合的相對 URI,才能形成所要求數據的絕對 URI。 如果 QueryString 屬性不是空字串,則會附加至 address。
注意
當您在應用程式中啟用網路追蹤時,此成員會輸出追蹤資訊。 如需詳細資訊,請參閱 .NET Framework 中的網路追蹤。