準備
(なし)
デザイン
- フォーム (Form1) にボタン (button1) を配置します。
- フォーム (Form1) にリストボックス (listBox1) を配置します。
サンプルコード (C#)
using System.IO;
using System.Xml;
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)
{
Invoice();
}
private async void Invoice()
{
string InvoiceAddress = "https://web-api.invoice-kohyo.nta.go.jp/1/num?";
string APIKey = "ABCDEFGHIJKLM";
string InvoceNo = "T9420001000213";
string URL = $@"{InvoiceAddress}id={APIKey}&number={InvoceNo}&type=11&history=0";
var httpClient = new HttpClient();
httpClient.DefaultRequestHeaders.Add("User-Agent", "Mozilla");
var response = await httpClient.GetAsync(URL);
var contents = await response.Content.ReadAsStringAsync();
string line = "";
using var sr = new StringReader(contents);
while ((line = sr.ReadLine()) != null)
{
listBox1.Items.Add(line);
}
}
}
}
解説
国税庁の WebAPI を利用して、インボイス情報を取得します。
結果
動作確認環境
Visual Studio 2022 Professional (.NET 7 C#11)
ログ
初版:2023.09.09 Visual Studio 2022 Professional (.NET 7 C#11)
