简体   繁体   English

curl 返回 HTTP 状态码 404 但页面可用

[英]curl returns HTTP status code 404 but page is available

I want to check the HTTP status code for a web UI (https://something/login.html) with curl on Linux. I want to check the HTTP status code for a web UI (https://something/login.html) with curl on Linux. So I wrote a little shell script doing the following:所以我写了一个小 shell 脚本执行以下操作:

#!/bin/sh
echo $(curl -sSLk -w '%{http_code}' -o /dev/null $1 2> /dev/null)

The problem is: this script returns 404 even if the queried web UI is available through the browser.问题是:即使查询的 web UI 可以通过浏览器访问,此脚本也会返回 404。 For other URLs the script returns valid values (status code 200).对于其他 URL,脚本返回有效值(状态代码 200)。

I further wrote a Python script for testing reasons:出于测试原因,我进一步写了一个 Python 脚本:

import requests
try:
   response = requests.get(
       "https://something/login.html",
       verify=False
   )   
   print(response.status_code)
except requests.ConnectionError:
   print("failed to connect")

this Python script returns status code 200 for the same URL for which curl returns 404.此 Python 脚本为相同的 URL 返回状态代码 200,而 curl 返回 404。

Thanks for your help in advance.提前感谢您的帮助。

They detected what you were trying to do.他们检测到你试图做什么。 Some sites return a Forbidden or Not Authoriozed.一些网站返回禁止或未授权。
Any web app can return any HTTP Status Code.任何 web 应用程序都可以返回任何 HTTP 状态代码。

Just using a UA is not sufficient.仅使用 UA 是不够的。 Using an obscure UA that cannot be profiled may (or may not) help.使用无法分析的模糊 UA 可能(或可能不会)有帮助。 It has worked for me a few times.它对我有用几次。

CloudFlare is using the UA for profiling. CloudFlare 正在使用 UA 进行分析。 One of the things they do is watch the SSL handshaking.他们做的一件事是观看 SSL 握手。 Browsers do not all use the same algorithm and CloudFlare finds the idiosyncrasies between various Browsers.浏览器并非都使用相同的算法,CloudFlare 会发现各种浏览器之间的特性。 You have to have all the cookies.您必须拥有所有 cookies。 Many will do a 304 redirect back to them selves after setting some cookie and check for the cookie.许多人会在设置一些 cookie 并检查 cookie 后自己进行 304 重定向。 If you do not have JavaScript you can be blocked.如果您没有 JavaScript,您可能会被阻止。


Without the URL I cannot tell you much.没有 URL 我不能告诉你太多。 There is a learning curve, and a fairly steep one.有一个学习曲线,而且相当陡峭。

If I can enter a site using a Browser without JavaScript, I can always get in with curl.如果我可以使用没有 JavaScript 的浏览器进入站点,我总是可以使用 curl 进入。
Some are still very difficult.有些仍然非常困难。 I like the ones that put all the data I want in a JavaScript JSON object.我喜欢将我想要的所有数据放入 JavaScript JSON object 中的那些。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM