Debian Server 上的 wget 获得 302 Found 而 Manjaro 上的 wget 获得 200 OK
wget on Debian Server gets 302 Found while wget on Manjaro gets 200 OK
我正在使用 wget 从 URL https://www.instagram.com/instagram/?__a=1 检索 Instagram JSON。
运行 wget 从我的本地 Manjaro 设置 returns 一个 200 OK
和正确的 JSON 响应,但是 运行 它从 Debian 服务器检索一个302 found
.
起初我认为可能是因为wget版本不同,但是运行本地curl也可以,而wget不能正常工作。
我应该在我的服务器上设置什么以获得正确的响应吗?我的猜测是 HTTPS 连接拒绝我的服务器正确连接。
所以,这是 Instagram 服务器的一个怪癖。你对此无能为力。
问题是 Instagram 会根据您是通过 IPv4 还是 IPv6 连接到他们的服务器做出不同的响应。为什么他们会这样做超出了我的范围,但我可以通过仅控制此变量来可靠地重现结果。
IPv4:
$ wget -O/dev/null -4 "https://www.instagram.com/instagram/?__a=1"
--2020-09-03 14:22:15-- https://www.instagram.com/instagram/?__a=1
Resolving www.instagram.com (www.instagram.com)... 157.240.27.174
Connecting to www.instagram.com (www.instagram.com)|157.240.27.174|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 118552 (116K) [application/json]
Saving to: ‘/dev/null’
100%[================================================================================================================================>] 118,552 306KB/s in 0.4s
2020-09-03 14:22:17 (306 KB/s) - ‘/dev/null’ saved [118552/118552]
IPv6:
$ wget -O/dev/null -6 "https://www.instagram.com/instagram/?__a=1"
--2020-09-03 14:22:54-- https://www.instagram.com/instagram/?__a=1
Resolving www.instagram.com (www.instagram.com)... 2a03:2880:f23f:e5:face:b00c:0:4420
Connecting to www.instagram.com (www.instagram.com)|2a03:2880:f23f:e5:face:b00c:0:4420|:443... connected.
HTTP request sent, awaiting response... 302 Found
Cookie coming from www.instagram.com attempted to set domain to www.instagram.com
Cookie coming from www.instagram.com attempted to set domain to www.instagram.com
Location: https://www.instagram.com/accounts/login/?next=/instagram/%3F__a%3D1 [following]
--2020-09-03 14:22:54-- https://www.instagram.com/accounts/login/?next=/instagram/%3F__a%3D1
Reusing existing connection to [www.instagram.com]:443.
HTTP request sent, awaiting response... 200 OK
Cookie coming from www.instagram.com attempted to set domain to www.instagram.com
Cookie coming from www.instagram.com attempted to set domain to www.instagram.com
Length: 48094 (47K) [text/html]
Saving to: ‘/dev/null’
100%[================================================================================================================================>] 48,094 --.-K/s in 0.04s
2020-09-03 14:22:54 (1.28 MB/s) - ‘/dev/null’ saved [48094/48094]
这与您在调试日志中看到的相同。在 Manjaro 上,它建立 IPv4 连接,而在 Debian 上,它建立 IPv6 连接,这导致了差异。
欢迎来到疯狂的网络服务器世界:)
无论如何,您的问题的答案是仅使用 IPv4 连接
我正在使用 wget 从 URL https://www.instagram.com/instagram/?__a=1 检索 Instagram JSON。
运行 wget 从我的本地 Manjaro 设置 returns 一个 200 OK
和正确的 JSON 响应,但是 运行 它从 Debian 服务器检索一个302 found
.
起初我认为可能是因为wget版本不同,但是运行本地curl也可以,而wget不能正常工作。
我应该在我的服务器上设置什么以获得正确的响应吗?我的猜测是 HTTPS 连接拒绝我的服务器正确连接。
所以,这是 Instagram 服务器的一个怪癖。你对此无能为力。
问题是 Instagram 会根据您是通过 IPv4 还是 IPv6 连接到他们的服务器做出不同的响应。为什么他们会这样做超出了我的范围,但我可以通过仅控制此变量来可靠地重现结果。
IPv4:
$ wget -O/dev/null -4 "https://www.instagram.com/instagram/?__a=1"
--2020-09-03 14:22:15-- https://www.instagram.com/instagram/?__a=1
Resolving www.instagram.com (www.instagram.com)... 157.240.27.174
Connecting to www.instagram.com (www.instagram.com)|157.240.27.174|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 118552 (116K) [application/json]
Saving to: ‘/dev/null’
100%[================================================================================================================================>] 118,552 306KB/s in 0.4s
2020-09-03 14:22:17 (306 KB/s) - ‘/dev/null’ saved [118552/118552]
IPv6:
$ wget -O/dev/null -6 "https://www.instagram.com/instagram/?__a=1"
--2020-09-03 14:22:54-- https://www.instagram.com/instagram/?__a=1
Resolving www.instagram.com (www.instagram.com)... 2a03:2880:f23f:e5:face:b00c:0:4420
Connecting to www.instagram.com (www.instagram.com)|2a03:2880:f23f:e5:face:b00c:0:4420|:443... connected.
HTTP request sent, awaiting response... 302 Found
Cookie coming from www.instagram.com attempted to set domain to www.instagram.com
Cookie coming from www.instagram.com attempted to set domain to www.instagram.com
Location: https://www.instagram.com/accounts/login/?next=/instagram/%3F__a%3D1 [following]
--2020-09-03 14:22:54-- https://www.instagram.com/accounts/login/?next=/instagram/%3F__a%3D1
Reusing existing connection to [www.instagram.com]:443.
HTTP request sent, awaiting response... 200 OK
Cookie coming from www.instagram.com attempted to set domain to www.instagram.com
Cookie coming from www.instagram.com attempted to set domain to www.instagram.com
Length: 48094 (47K) [text/html]
Saving to: ‘/dev/null’
100%[================================================================================================================================>] 48,094 --.-K/s in 0.04s
2020-09-03 14:22:54 (1.28 MB/s) - ‘/dev/null’ saved [48094/48094]
这与您在调试日志中看到的相同。在 Manjaro 上,它建立 IPv4 连接,而在 Debian 上,它建立 IPv6 连接,这导致了差异。 欢迎来到疯狂的网络服务器世界:)
无论如何,您的问题的答案是仅使用 IPv4 连接