如何正确解压并查看使用curl从对网站API的POST请求获得的响应

问题描述 投票:0回答:1

我正在尝试使用curl 命令行向网站的API 发送POST 请求。我通过数据包嗅探获得了请求标头和正文。执行curl命令后,响应将保存在

output.txt
中。然而,经过检查,该文件以意外的格式出现。可以根据标头使用 gzip、deflate 或 Brotli 来压缩响应。我尝试过使用
brotli
inflate
zcat
gzip -d
等各种命令来解压缩文件,但都没有成功。如何正确解压并查看
output.txt
中的响应?


url = https://www.my_site.com/api/register

Accept: */*

Accept-Encoding: gzip, deflate, br

Accept-Language: en-US,en;q=0.5

Alt-Used: www.my_site.com

Connection: keep-alive

Content-Length: 134

content-type: application/json

Cookie: cf_clearance=uvzZt00yfK5h2O_SEVu2YPNL.5cJT9AnkYJr9YhwhoU-1706709249-1-AUHiOWO+oTJ91OHoTxQWgHVGPNkJF+yqyHbsLFotZWuDb2Uivu/a/ETDZP5fupnkUX6z9mt/+nRhMTEZ7jPmT5c=

Host: www.my_site.com

Origin: https://www.my_site.com

Referer: https://www.my_site.com/?ref=bJsbQYkc

Sec-Fetch-Dest: empty

Sec-Fetch-Mode: cors

Sec-Fetch-Site: same-origin

User-Agent: Mozilla/5.0 (X11; Linux aarch64; rv:109.0) Gecko/20100101 Firefox/115.0

Body:

{"username":"my_phone_no","password":"xGxfUu4ljy9yR8n","captcha":"hF5X","ref":"bJsbQYkc","phone":"my_phone_no","rand":"9142","opt":"hF5X"}


curl -X POST https://www.my_site.com/api/register \

-H "Accept: */*" \

-H "Accept-Encoding: gzip, deflate, br" \

-H "Accept-Language: en-US,en;q=0.5" \

-H "Alt-Used: www.my_site.com" \

-H "Connection: keep-alive" \

-H "Content-Length: 134" \

-H "Content-Type: application/json" \

-H "Cookie: cf_clearance=uvzZt00yfK5h2O_SEVu2YPNL.5cJT9AnkYJr9YhwhoU-1706709249-1-AUHiOWO+oTJ91OHoTxQWgHVGPNkJF+yqyHbsLFotZWuDb2Uivu/a/ETDZP5fupnkUX6z9mt/+nRhMTEZ7jPmT5c=" \

-H "Host: www.supercharles.day" \

-H "Origin: https://www.my_site.com" \

-H "Referer: https://www.my_site.com/?ref=bJsbQYkc" \

-H "Sec-Fetch-Dest: empty" \

-H "Sec-Fetch-Mode: cors" \

-H "Sec-Fetch-Site: same-origin" \

-H "User-Agent: Mozilla/5.0 (X11; Linux aarch64; rv:109.0) Gecko/20100101 Firefox/115.0" \

-d '{"username":"my_phone_no","password":"xGxfUu4ljy9yR8n","captcha":"hF5X","ref":"bJsbQYkc","phone":"my_phone_no","rand":"9142","opt":"hF5X"}' \

-o output.txt


┌──(kali㉿localhost)-[~]

└─$ cat output.txt

�#��ړ�Y��>��!S�K�)�*�sQ⚆a)�{��ה��ˑ7���$�|HVJ9.ǫ�p�}9���

以下是我在解压文件过程中尝试过的命令

output.txt

┌──(kali㉿localhost)-[~]

└─$ brotli -d output.txt

input file [output.txt] suffix mismatch
┌──(kali㉿localhost)-[~]

└─$ inflate output.txt

Usage: inflate [OPTIONS] START END [AMOUNT]

Try 'inflate --help' for help.

Error: Invalid value for 'START': 'output.txt' is not a valid integer.
┌──(kali㉿localhost)-[~]

└─$ zcat output.txt

gzip: output.txt: not in gzip format
┌──(kali㉿localhost)-[~]

└─$ gzip -d output.txt

gzip: output.txt: unknown suffix -- ignored
curl request compression httpwebresponse
1个回答
0
投票
  1. 重命名文件以指示 Brotli 压缩:
mv output.txt output.txt.br
  1. 删除原文件:
rm output.txt
  1. 解压Brotli文件:
brotli -d output.txt.br

执行这些命令后,解压缩的响应应该在新创建的output.txt中可用。这为我解决了这个问题,我希望它可以帮助其他面临类似问题的人。

© www.soinside.com 2019 - 2024. All rights reserved.