3
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

JavaでとりあえずWeb APIを叩く方法

Last updated at Posted at 2022-01-13

JavaでAPIを叩く方法でつまづいたので書き記す

とりあえず公開されているAPIを叩きたい人向け
もっといい方法ありそうですが書いておきます

importするライブラリ

import java.net.URL;
import java.io.*;

コード

        final String endpoint = "任意のURL";

                // ここではkeyとidのパラメータが必要な場合を書きます。必要ない人は飛ばしてください。
        final String key = "パラメータ必要な人は";
        final String Id = "任意で";

                // パラメータが複数ある人はidのように&で繋げてください。
        String url = endpoint + "?key=" + key + "&id=" + Id;
        URL obj = new URL(url);
        InputStreamReader streamReader = new InputStreamReader( obj.openStream() );
        BufferedReader bufferedReader = new BufferedReader( streamReader );
        String content = bufferedReader.readLine()
        System.out.println(content);
3
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?