ant 的 get 任务抛出 IOException
ant's get task throws IOException
我正在设置一个 ant 任务来轮询我的应用程序的端点以获取健康状态,此任务的输出应该只显示端点的 json 输出,这是我尝试过的
<target name="status">
<get src="http://127.0.0.1:8840/-/system/get_health" dest="${dir.tmp}/status" />
<loadfile property="status" srcFile="${dir.tmp}/status" />
<echo message="${status}" />
</target>
以上是在 get
上抛出以下错误
[get] Getting: http://127.0.0.1:8840/-/system/get_health
[get] To: C:\path\to\build\tmp\status
[get] Error opening connection java.io.IOException: Invalid Http response
[get] Can't get http://127.0.0.1:8840/-/system/get_health to C:\path\to\build\tmp\status
get
期望返回的格式到底是什么?
据我所知,这是纯文本输出,没有headers.
我可以使用 curl 和 chrome 查看输出。
$curl http://127.0.0.1:8840/-/system/get_health
{"status": "HEALTHY"}
有什么方法可以忽略这个错误并保存输出吗?或者还有其他方法吗?
编辑
运行
$ant status -debug
除了已经发布的内容外,没有提供任何有用的输出。
$curl -v http://127.0.0.1:8840/-/system/get_health
* STATE: INIT => CONNECT handle 0x6000578b0; line 1108 (connection #-5000)
* Added connection 0. The cache now contains 1 members
* Trying 127.0.0.1...
* STATE: CONNECT => WAITCONNECT handle 0x6000578b0; line 1161 (connection #0)
* Connected to 127.0.0.1 (127.0.0.1) port 8840 (#0)
* STATE: WAITCONNECT => SENDPROTOCONNECT handle 0x6000578b0; line 1260 (connection #0)
* STATE: SENDPROTOCONNECT => DO handle 0x6000578b0; line 1278 (connection #0)
> GET /-/system/get_health HTTP/1.1
> Host: 127.0.0.1:8840
> User-Agent: curl/7.48.0
> Accept: */*
>
* STATE: DO => DO_DONE handle 0x6000578b0; line 1357 (connection #0)
* STATE: DO_DONE => WAITPERFORM handle 0x6000578b0; line 1484 (connection #0)
* STATE: WAITPERFORM => PERFORM handle 0x6000578b0; line 1494 (connection #0)
* Increasing bytecount by 23 from hbuflen
{"status": "HEALTHY"}
* nread <= 0, server closed connection, bailing
* STATE: PERFORM => DONE handle 0x6000578b0; line 1652 (connection #0)
* Curl_done
* Connection #0 to host 127.0.0.1 left intact
* Expire cleared
尝试查看 here。这可能是因为 return 值中的特殊字符。字符串需要编码。
有趣的是,这在我使用的网络套接字处理程序中执行不佳,因为它实际上从未在响应中返回状态行。
我不得不使用 netcat 查看来自服务器的原始数据:
$ echo -e "GET /-/system/get_health HTTP/1.1\n\n" | nc 127.0.0.1 8840
{"status": "HEALTHY"}
$
不符合正确的 HTTP 规范
$ echo -e "GET /-/system/get_health HTTP/1.1\n\n" | nc 127.0.0.1 8840
HTTP/1.1 200 OK
{"status": "HEALTHY"}
$
这很奇怪,因为 chrome 和 curl 似乎都盲目地忽略了它。
修复此问题后,ant 解析响应没有问题。
我正在设置一个 ant 任务来轮询我的应用程序的端点以获取健康状态,此任务的输出应该只显示端点的 json 输出,这是我尝试过的
<target name="status">
<get src="http://127.0.0.1:8840/-/system/get_health" dest="${dir.tmp}/status" />
<loadfile property="status" srcFile="${dir.tmp}/status" />
<echo message="${status}" />
</target>
以上是在 get
[get] Getting: http://127.0.0.1:8840/-/system/get_health
[get] To: C:\path\to\build\tmp\status
[get] Error opening connection java.io.IOException: Invalid Http response
[get] Can't get http://127.0.0.1:8840/-/system/get_health to C:\path\to\build\tmp\status
get
期望返回的格式到底是什么?
据我所知,这是纯文本输出,没有headers.
我可以使用 curl 和 chrome 查看输出。
$curl http://127.0.0.1:8840/-/system/get_health
{"status": "HEALTHY"}
有什么方法可以忽略这个错误并保存输出吗?或者还有其他方法吗?
编辑
运行
$ant status -debug
除了已经发布的内容外,没有提供任何有用的输出。
$curl -v http://127.0.0.1:8840/-/system/get_health
* STATE: INIT => CONNECT handle 0x6000578b0; line 1108 (connection #-5000)
* Added connection 0. The cache now contains 1 members
* Trying 127.0.0.1...
* STATE: CONNECT => WAITCONNECT handle 0x6000578b0; line 1161 (connection #0)
* Connected to 127.0.0.1 (127.0.0.1) port 8840 (#0)
* STATE: WAITCONNECT => SENDPROTOCONNECT handle 0x6000578b0; line 1260 (connection #0)
* STATE: SENDPROTOCONNECT => DO handle 0x6000578b0; line 1278 (connection #0)
> GET /-/system/get_health HTTP/1.1
> Host: 127.0.0.1:8840
> User-Agent: curl/7.48.0
> Accept: */*
>
* STATE: DO => DO_DONE handle 0x6000578b0; line 1357 (connection #0)
* STATE: DO_DONE => WAITPERFORM handle 0x6000578b0; line 1484 (connection #0)
* STATE: WAITPERFORM => PERFORM handle 0x6000578b0; line 1494 (connection #0)
* Increasing bytecount by 23 from hbuflen
{"status": "HEALTHY"}
* nread <= 0, server closed connection, bailing
* STATE: PERFORM => DONE handle 0x6000578b0; line 1652 (connection #0)
* Curl_done
* Connection #0 to host 127.0.0.1 left intact
* Expire cleared
尝试查看 here。这可能是因为 return 值中的特殊字符。字符串需要编码。
有趣的是,这在我使用的网络套接字处理程序中执行不佳,因为它实际上从未在响应中返回状态行。
我不得不使用 netcat 查看来自服务器的原始数据:
$ echo -e "GET /-/system/get_health HTTP/1.1\n\n" | nc 127.0.0.1 8840
{"status": "HEALTHY"}
$
不符合正确的 HTTP 规范
$ echo -e "GET /-/system/get_health HTTP/1.1\n\n" | nc 127.0.0.1 8840
HTTP/1.1 200 OK
{"status": "HEALTHY"}
$
这很奇怪,因为 chrome 和 curl 似乎都盲目地忽略了它。
修复此问题后,ant 解析响应没有问题。