跳转到内容
View in the app

A better way to browse. Learn more.

彼岸论坛

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.
欢迎抵达彼岸 彼岸花开 此处谁在 -彼岸论坛

[程序员] 我也写了一个堪称愚蠢的小工具(用来打印接收到的 HTTP 请求)

发表于

受到 我写了一个堪称愚蠢的小工具 鼓舞,遂决定把 23 年写的一个工具发出来,ddrpa/corgi 可以用来打印收到的 HTTP 请求。

这个工具本质上是对下面这段脚本的扩展:

listen_port () {
	while true
	do
		{
			echo -e 'HTTP/1.1 200 OK\r\n'
		} | nc -l -v $1
		echo '\r\n'
	done
}

支持的功能有:

$ ./corgi -h
usage: corgi [-h|--help] [-p|--port <integer>] [--max-printable-size <integer>]
             [--pretty] [--fetch "<value>"]

             Corgi HTTP Request Logger, version 1.1.0

Arguments:

  -h  --help                Print help information
  -p  --port                监听指定端口. Default: 8000
      --max-printable-size  请求体最大打印长度( 0
                            表示不截断),JSON 和 URLEncoded
                            表单不受影响). Default: 256
      --pretty              特定类型请求体输出美化
      --fetch               转发请求到指定地址

对接调试接口时,可以在代码有错误(或一行代码都没写)的情况下知道对方发送了什么。

效果演示(监听 8000 端口,打印收到的 HTTP 请求):

$ ./corgi -p 8000 --pretty

2023/07/06 16:27:32 corgi is waiting on :8000
2023/07/06 16:27:38 POST /proxy?url=/iot/alipayApi/faceAuth/getAlipayUserInfo HTTP/1.1
RemoteAddr: [::1]:57382
Host: localhost:8000
cookie: Cookie_1=value
authorization: Bearer Igp5d444444444444444
user-agent: PostmanRuntime/7.32.3
accept: */*
accept-encoding: gzip, deflate, br
content-type: application/x-www-form-urlencoded
content-length: 98
postman-token: 9a00e0be-f921-4605-b2f3-b577c1e263c2
connection: keep-alive

payload={"username":"admin","password":"wecsnuigb43j@_f"}
method=PATCH

为什么说这个工具很愚蠢,因为:

  1. 双方把对接文档写清楚,或使用 Swagger 之类的工具的话,就不需要这样调试了;
  2. 我发现有的项目都进预发布环节了,才发现对接有误。因此这个工具是 Golang 编写的,方便直接从 GitHub Release 页面下载二进制文件到预发布环境;

要是您觉得这个小工具愚蠢的比较清澈的话,我还有一堆

Featured Replies

No posts to show

创建帐户或登录来提出意见

Account

导航

搜索

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.