首页 文章

如何使用curl获取http响应的时间戳

提问于
浏览
3

我正在使用curl通过http post请求命中服务器并使用以下代码发送xml作为请求主体:

curl -X POST -d @path to xml file URL

Ex: curl -X POST -d @C:\docs\test.xml http://www.example.com

成功返回json http响应如下:

"header": {
    "product": "xxxxxxxxxx",
    "version": "xxxxxxxx"
},
"status": {
    "elapsedTime": 329,
    "httpReturnCode": 200,
    "statusCode": 0,
    "success": true,
    "startTime": 1350387905444,
    "statusDescription": "Successful"
},

但是这个json响应没有显示endTime时间戳,即webservice调用返回的时间 .

我知道从curl找到url响应时间的方法,使用命令:

curl -o /dev/null -w "Connect: %{time_connect} TTFB: %{time_starttransfer} Total time: %{time_total} n" http://www.google.com

以上命令以毫秒为单位返回响应时间 . 有什么办法可以使用curl获取http响应的时间戳吗?我的要求是使用带有请求主体(XML文件)的http POST命中服务器,然后根据时间戳获取响应时间 . 任何帮助是极大的赞赏 .

1 回答

  • 1

    解决此问题的一种方法是包括curl由环境变量调用的时间 . 然后,您可以计算之后响应时间的绝对时间 .

    在Windows中,这将是

    curl.exe -o NUL -w "Time: %TIME% Connect: %{time_connect} TTFB: %{time_starttransfer} Total time: %{time_total}\n" http://www.google.com
    

相关问题