简体   繁体   English

如何从在Play框架上运行的网站获取http状态

[英]How to get http status from a website run on the play framework

Please forgive my ignorance. 请原谅我的无知。 I don't know anything about the play framework, or the MVC design pattern so please bear with me. 我对播放框架或MVC设计模式一无所知,所以请多多包涵。

I need to write a shell script to check if our service is still up. 我需要编写一个shell脚本来检查我们的服务是否仍然可用。 I had planned to use curl to get the http response code and check if it's a 200 or 404. We are using the play framework and designing the site using the MVC design pattern. 我曾计划使用curl获取http响应代码,并检查它是200还是404。我们正在使用play框架,并使用MVC设计模式来设计站点。 I know nothing about these 2 things so it might be adding to my confusion. 我对这两件事一无所知,因此可能会增加我的困惑。

Anyway, the website is up because I checked in Chrome and FF and it's up and working. 无论如何,该网站已启动,因为我已登录Chrome和FF,并且该网站已启动且可以正常工作。 I ran this curl command, which should give me a 200: 我运行了curl命令,应该给我200:

curl -I http://oursite.com:8080
HTTP/1.1 404 Not Found
Content-Type: text/html; charset=utf-8
Content-Length: 1900

As a return code in the header, I get a 404. I don't know much about web technology but I read up on 404 status codes from wikipedia and it seems like it's looking for a index.html page (or whatever the requested page is). 作为标头中的返回码,我得到了404。我对网络技术了解不多,但是我从Wikipedia中读取了404状态码,似乎正在寻找index.html页面(或所请求的任何页面)是)。 I found a /dir/of/play/deployment/public directory on our server. 我在我们的服务器上找到了/ dir / of / play / deployment / public目录。 I blindly created an index.html in it but it didn't help. 我盲目地在其中创建了index.html,但它没有帮助。 I still got a 404 when I was expecting a 200. 当我期望200时,我仍然得到404。

I also tried using wget. 我也尝试使用wget。 wget gives me a 200, but it downloads the contents of the main page to my local acct to a file called index.html. wget给我200,但是它将主页的内容下载到我的本地帐户中,该文件名为index.html。 I ran 我跑了

wget http://oursite.com:8080
--2014-01-29 19:42:42--  http://oursite.com:8080/
Resolving oursite.com... 10.64.8.76
Connecting to oursite.com|10.64.8.76|:8080... connected.
HTTP request sent, awaiting response... 200 OK
Length: 27181 (27K) [text/html]
Saving to: “index.html”

I also ran another wget command but this one gave me a 404. I used the spider option to not download the file locally. 我还运行了另一个wget命令,但是该命令给了我404。我使用了Spider选项,而不是在本地下载文件。

wget --spider http://oursite.com:8080
Spider mode enabled. Check if remote file exists.
--2014-01-29 19:42:42--  http://oursite.com:8080/
Resolving oursite.com... 10.64.8.76
Connecting to oursite.com|10.64.8.76|:8080... connected.
HTTP request sent, awaiting response... 404 Not Found
Remote file does not exist -- broken link!!!

The output of the last command said there's a remote file that it's looking for but can't find. 最后一条命令的输出说有一个远程文件正在查找,但找不到。 However, clearly the site was sending some content when it wasn't in spider mode thanks to the creation/existence of the index.html pg in my local dir. 但是,很显然,由于本地目录中index.html pg的创建/存在,因此该网站在未处于蜘蛛模式时正在发送一些内容。

So the question is, what is this page that curl and "wget --spider" looking for and why did plain wget "find" this file and download its contents? 因此,问题是,curl和“ wget --spider”要查找的页面是什么?为什么普通wget会“查找”此文件并下载其内容? Am I approaching this problem correctly (using curl or wget to see if the webservice is up and running) or am I attacking this problem wrong and should use something else to check? 我是在正确解决此问题(使用curl或wget来查看Web服务是否已启动并正在运行),还是我在错误地解决此问题,应该使用其他方法进行检查?

Thanks in advance for your help. 在此先感谢您的帮助。

I suspect this is due to: 我怀疑这是由于:

https://github.com/playframework/playframework/issues/2280 https://github.com/playframework/playframework/issues/2280

You'll need to make a regular GET call instead with an -i: 您需要使用-i进行常规的GET调用:

curl -is http://myapp.com | awk '/HTTP\/1.1 (.*) (.*?)/ {print $2}'

This should return 200 all is working. 这应该返回200一切正常。

One tip: in Chrome developer tools, in the network tab you can right click a request and 'Copy as cUrl'. 提示:在Chrome开发人员工具的网络标签中,您可以右键单击请求,然后单击“复制为cUrl”。 You could compare this request with your handwritten cUrl request. 您可以将此请求与您的手写cUrl请求进行比较。

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

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