準備
(なし)
デザイン
- フォーム (Form1) にボタン (button1) を配置します。
- フォーム (Form1) にテキストボックス (textBox1) を配置します。
サンプルコード (C#)
using System.Net;
using System.Web;
namespace WinFormsApp1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void button1_Click(object sender, EventArgs e)
{
string LoginUSR = "tanaka";
string LoginPWD = "9999";
string GSAddress = "http://192.168.2.122:8080/gsession";
string GSAPI = "/api/smail/send.do?";
string usrSid = "102";
string Title = "こんにちは。";
Title = HttpUtility.UrlEncode(Title);
string Body = "これはテストショートメッセージです。";
Body = HttpUtility.UrlEncode(Body);
textBox1.Text = $@"{GSAddress}{GSAPI}usrSid={usrSid}&title={Title}&body={Body}";
var clientInfo = new HttpClientHandler
{
Credentials = new NetworkCredential(LoginUSR, LoginPWD)
};
var client = new HttpClient(clientInfo);
var response = client.GetAsync(textBox1.Text).Result;
var result = response.Content.ReadAsStringAsync().Result;
textBox2.Text = result;
}
}
}
解説
GroupSession の /api/smail/send.do? をコールすることで、ショートメールを送信できます。このサンプルでは、ログインしたユーザーからユーザー 102 に送信しています。
結果
動作確認環境
Visual Studio 2022 Professional (.NET8 C#12)
ログ
初版:2024.02.27 Visual Studio 2022 Professional (C#12)
