Linux libcurl 消息的含义和执行过程

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/19109725/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-07 00:58:26  来源:igfitidea点击:

Meaning of libcurl messages and execution process

clinuxcurllibcurl

提问by harshal bhavsar

I am using libcurllibrary to fetch abc-1.tarfile from server. I want to know meaning of message which is display and process of execution of libcurlto display this messages.

我正在使用libcurlabc-1.tar从服务器获取文件。我想知道消息的含义,即libcurl显示此消息的显示和执行过程。

For Example: I provide some messages below out of that I know basic message meaning like Content-Lengthmeans length of file which are downloaded, etc.

例如:我在下面提供了一些消息,其中我知道基本消息的含义,例如Content-Length下载的文件长度等。

I want meaning of all messages, particularly messages which are start with *(e. g. Connection #0 to host (nil) left intact)

我想要所有消息的含义,特别是以*(例如Connection #0 to host (nil) left intact)开头的消息

* Re-using existing connection! (#0) with host (nil)
* Connected to (nil) (182.72.67.14) port 65101 (#0)
GET /...... HTTP/1.1
Host: 182.72.67.14:65101
Accept: */*
Connection:keep-alive
< HTTP/1.1 200 OK
< Cache-Control: private
< Content-Length: 186368
< Content-Type: application/x-tar
< Server: Microsoft-IIS/7.5
< Content-Disposition: attachment; filename=abc-1.tar
< X-AspNet-Version: 4.0.30319
< X-Powered-By: ASP.NET
< Date: Tue, 01 Oct 2013 06:29:00 GMT
< 
* Connection #0 to host (nil) left intact

回答by Arya

Marked by <are HTTP headers.You can read in detail about http headers and their meaning hereand marked by *are verbose information provided by curlwhich is displayed on stderr.

标记<为 HTTP 标头。您可以在此处阅读有关 http 标头及其含义*的详细信息, 并标记curl为显示在 上的详细信息stderr

回答by Eitan T

cURL's Man Pagespecifies three types of "special" verbose output:

cURL 的手册页指定了三种类型的“特殊”详细输出:

A line starting with '>' means "header data" sent by curl, '<' means "header data" received by curl that is hidden in normal cases, and a line starting with '*' means additional info provided by curl.

'>'开头的一行表示curl发送的“header data”,'<'表示curl收到的正常情况下隐藏的“header data”,'*'开头的行表示curl提供的附加信息。

You can read about HTTP header fieldsin the HTTP official publication page. Any other output lines displayed by cURL belong to the HTTP body carried by the corresponding message.

您可以在HTTP 官方发布页面 中阅读有关HTTP 标头字段的信息。cURL 显示的任何其他输出行都属于相应消息携带的 HTTP 正文。

So what is the actual meaning of these informationals starting with *, you ask? They inform you about the status of the transfer's TCP connection with the host. For instance:

那么这些以 开头的信息的实际含义是什么*,你问?它们会通知您与主机的传输 TCP 连接的状态。例如:

  • "Connected to (nil) (182.72.67.14) port 65101 (#0)"means that a TCP connection is established with the server side (in your case: 182.72.67.14). The #0is the TCP session number (which is used only by cURL). The nilindicates that the host name couldn't be resolved via DNS (had it been resolved, the it would've appeared instead of nil).

  • "Connection #0 to host (nil) left intact"means that although the transfer is over, the TCP session itself is still open (i.eno FIN/ACK exchanges have been made), allowing you to keep reusing the same TCP connection for multiple transfers (which could be useful if you don't want to sacrifice time on opening a new TCP connection).

    The message "Re-using existing connection! (#0) with host (nil)"supports that, indicating that cURL does indeed that, riding an existing TCP connection (from a previous transfer).

  • "Connected to (nil) (182.72.67.14) port 65101 (#0)"意味着与服务器端建立了 TCP 连接(在您的情况下:182.72.67.14)。的#0是TCP会话编号(由卷曲仅使用)。该nil指示主机名未能通过DNS解析(已经是解决了,它会一直出现,而不是nil)。

  • "Connection #0 to host (nil) left intact"意味着虽然传输结束了,TCP 会话本身仍然是打开的(没有进行 FIN/ACK 交换),允许您继续重复使用相同的 TCP 连接进行多次传输(如果您不想要,这可能很有用以牺牲打开新 TCP 连接的时间)。

    该消息"Re-using existing connection! (#0) with host (nil)"支持这一点,表明 cURL 确实这样做了,利用现有的 TCP 连接(来自先前的传输)。