出于端到端测试的目的,我在Jenkins构建中运行curl以对servlet应用程序进行HTTP调用。
这是我的命令:
curl --fail -s -v <target-address>
该调用导致HTTP 500带有JSON输出,该输出描述了当我使用浏览器访问它时的错误原因。没关系。
但是,curl实际上只显示500,它抑制了响应负载。这是一个问题,因为为了弄清楚原因,我必须通过浏览器手动重现请求。我也希望curl打印响应负载。 这是curl输出(省略了一些内容):
[2020-06-26T09:14:00.433Z] + curl --fail -s -v <target-adddress>
[2020-06-26T09:14:00.433Z] * Expire in 0 ms for 6 (transfer 0x55829a1a6f50)
[2020-06-26T09:14:00.433Z] * Uses proxy env variable no_proxy == 'foobar
[2020-06-26T09:14:00.433Z] * Uses proxy env variable https_proxy == foobar
...
[2020-06-26T09:14:00.433Z] * Expire in 0 ms for 1 (transfer 0x55829a1a6f50)
[2020-06-26T09:14:00.433Z] * Trying 147.204.6.136...
[2020-06-26T09:14:00.433Z] * TCP_NODELAY set
[2020-06-26T09:14:00.433Z] * Expire in 200 ms for 4 (transfer 0x55829a1a6f50)
[2020-06-26T09:14:00.433Z] > User-Agent: curl/7.64.0
[2020-06-26T09:14:00.433Z] > Proxy-Connection: Keep-Alive
[2020-06-26T09:14:00.433Z] >
[2020-06-26T09:14:00.433Z] < HTTP/1.1 200 Connection established
[2020-06-26T09:14:00.433Z] <
[2020-06-26T09:14:00.433Z] * Proxy replied 200 to CONNECT request
[2020-06-26T09:14:00.433Z] * CONNECT phase completed!
[2020-06-26T09:14:00.433Z] * ALPN, offering h2
[2020-06-26T09:14:00.433Z] * ALPN, offering http/1.1
[2020-06-26T09:14:00.433Z] * successfully set certificate verify locations:
[2020-06-26T09:14:00.433Z] * CAfile: none
[2020-06-26T09:14:00.433Z] CApath: /etc/ssl/certs
[2020-06-26T09:14:00.433Z] } [5 bytes data]
[2020-06-26T09:14:00.433Z] * TLSv1.3 (OUT), TLS handshake, Client hello (1):
[2020-06-26T09:14:00.433Z] } [512 bytes data]
[2020-06-26T09:14:00.433Z] * CONNECT phase completed!
[2020-06-26T09:14:00.433Z] * CONNECT phase completed!
[2020-06-26T09:14:...
[2020-06-26T09:14:00.433Z] * SSL connection using TLSv1.2 / ECDHE-RSA-AES128-GCM-SHA256
[2020-06-26T09:14:00.433Z] * ALPN, server did not agree to a protocol
[2020-06-26T09:14:00.433Z] * Server certificate:
[2020-06-26T09:14:00.433Z] *
[2020-06-26T09:14:00.433Z] } [5 bytes data]
[2020-06-26T09:14:00.433Z] > GET <target-adddress>
[2020-06-26T09:14:00.433Z] > Host: foobar
[2020-06-26T09:14:00.433Z] > User-Agent: curl/7.64.0
[2020-06-26T09:14:00.433Z] > Accept: */*
[2020-06-26T09:14:00.433Z] >
[2020-06-26T09:14:10.659Z] { [5 bytes data]
[2020-06-26T09:14:10.659Z] * The requested URL returned error: 500
[2020-06-26T09:14:10.659Z] * Closing connection 0
如何参数化curl以显示响应有效载荷?
顺便说一句,我使用--fail
来让curl返回返回码<> 0(如果500返回),因为我需要在Jenkinsfile中对此情况做出反应。
答案 0 :(得分:0)
您要求,要求使用--fail
选项抑制有效载荷!删除该选项,您将获得完整的响应...