Get 部分を追加しました Windows8(C#) ストアアプリ : HttpClient で Get と Post する簡易クラス 非同期のメソッドを定義する場合は、async Task<T> とします。大抵の場合、メソッド化しておいたほうが使いやすいものとなります。
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;
namespace LBOX_Http
{
public class Lbox
{
public static async Task<string> Post(string url, Dictionary<string, string> param )
{
string result = "";
try
{
HttpClient httpClient = new HttpClient();
httpClient.MaxResponseContentBufferSize = int.MaxValue;
HttpContent content = new FormUrlEncodedContent(param);
var response = await httpClient.PostAsync(url, content);
String text = await response.Content.ReadAsStringAsync();
result = text;
}
catch (Exception Err)
{
result = "ERROR:" + Err.Message;
}
return result;
}
}
}
▼ 呼び出し方法
String url = "投稿先の URL";
var param = new Dictionary<string, string>();
param.Add("u", "入力文字列");
Response.Text = await Lbox.Post(url, param);
u は、HTML 定義で FORM 内の INPUT の name 属性に割り当てられた文字列です。 関連する記事 Win8 ストア : HttpClient + XDocument で RSS の取得 Win8 ストア : UrlEncode と UrlDecode
|
|
【Win8 ストアアプリの最新記事】
- C# : HttpClient で Post と Get する汎用 static クラス
- Win8.1 ストアアプリ(JS) : Visual Studio 2013 で Three.js(v65) の WebGLRenderer の動作を確認しました
- WinJS ストア : Three.js を組み込んで、『画像を飛ばす』テンプレート( Bird.js を利用 )
- WinJS ストア : 『背景画像をチェンジする2画面アプリ』のテンプレート
- VS2012ストア(C#) : WebView テンプレート
- VS2012(C#)ストア : ListView Twitter 検索テンプレート
- イラストを背景にして2ページの画面遷移を解りやすくした Windows Store テンプレート
- Twitter API の自分のアプリのトークンを使って投稿するだけの class VS2012_Twitter
- Win8 ストア(C#) / PDF viewer sample (Windows 8.1)
- ストアアプリの TextBox のスクロールバー
- Win8 ストアアプリの、メモリ上にページを残す画面遷移と、前画面のコントロールの参照
- Win8 ストアアプリで、『選択肢を応答するダイアログ』を簡単に使うための MessageBox クラス
- Win8ストア XAML の AppBarButtonStyle のContent に指定する 16進数 Unicode の取得
- Win8 ストア : UrlEncode と UrlDecode
- Win8 ストア : HttpClient + XDocument で RSS の取得
- Win8 ストア : リストボックス テンプレート
- Win8 ストア : ファイルアクセス テンプレート
- Win8 ストア : ストアブランク テンプレート
- AppBar テンプレート / Win8 ストアアプリ(C#)
- Windows ストアアプリの AppBar を作成してテストする






