はい、PostAsyncメソッドを使用します。
このメソッドは、インスタンスだけでなく、( WebClientクラスのメソッドUriと同様に)または文字列のいずれかを取ります。UploadStringHttpContent
インスタンスは、HttpContentさまざまなタイプのコンテンツに依存しないように設計されており、コンテンツを提供するメカニズム(バイトByteArrayContentの配列、StreamContentStreamなど)だけでなく、構造(MultipartFormDataContent)も指定できます。
そうは言っても、次のように文字列を送信するStringContentクラスもあります。
// コンテンツ。string post="投稿するコンテンツ";
// The client.
using (client = new HttpClient());
{
// Post.
// Let's assume you're in an async method.
HttpResponseMessage response = await client.Post(
"http://yourdomain/post", new StringContent(post));
// Do something with the response.
}
を指定する必要がある場合はEncoding、を受け取るコンストラクターがEncodingあります。これは次のように使用します。
// The client.
using (client = new HttpClient());
{
// Post.
// Let's assume you're in an async method.
HttpResponseMessage response = await client.Post(
"http://yourdomain/post", new StringContent(post),
Encoding.ASCII);
// Do something with the response.
}
そこからHttpResponseMessage、応答が送信されるときに処理することが問題になります(それが重要な場合、一方向の操作でない場合)。