2
0

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 3 years have passed since last update.

細かいことはいいから特定のAPIエンドポイントのOkHttpログをtailする

Posted at

Androidの開発をしてると、特定のAPIに対するリクエストとレスポンスを確認したいことって、あると思います。

普通にlogcatを眺めるだけだと、目的外のログもぶわぁーって出てしまって涙目ですよね。

皆どうしてるんですかね?私はこうしてます。(pidcatを利用)

以下、v1/users/register というパスを含むリクエストとレスポンスを確認するとします。

リクエストを確認

コマンド
pidcat com.sample.package -t OkHttp | awk '/-->.*v1\/users\/register, /--> END/'
ログ
                 OkHttp  D  --> POST https://api.sample.com/v1/users/register http/1.1
                         D  Content-Type: application/json; charset=UTF-8
                         D  Content-Length: 170
                         D  {"user":{"app_version":"2.4.0","device_id":"5a3fe389-da50-4083-a811-24c77093e64b","device_name":"generic_x86","os_type":"Android","os_version":"9"}}
                         D  --> END POST (170-byte body)

レスポンスを確認

コマンド
pidcat com.sample.package -t OkHttp | awk '/<--.*v1\/users\/register, /<-- END/'
ログ

                         D  <-- 200  https://api.sample.com/v1/users/register (8942ms)
                         D  date: Wed, 05 Feb 2020 00:24:05 GMT
                         D  content-type: application/json; charset=utf-8
                         D  server: nginx
                         D  vary: Accept-Encoding
                         D  cache-control: no-cache
                         D  x-runtime: 0.110749
                         D  x-frame-options: deny
                         D  {"status": 200}
                         D  <-- END HTTP (17-byte body)

awkして、該当のログを引っこ抜いているだけなので、特に解説はしません。

細かいツッコミはなしで。。。

2
0
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
2
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?