使用HTTP/1.1协议的curl,发送一个请求,在post数据量超过1K的时候,接口会返回: HTTP/1.1 100 Continue HTTP/1.1 200 OK Date: Sat, 07 Dec 2013 10:09:11 GMT Server: Apache/2.2.24 (Unix) PHP/5.3.25 X-Powered-By: PHP/5.3.25 Content-Length: 43 Content-Type: text/html 从表面上看,100 Continue表明请求一次没发送完,需要继续发送;搜索后看到现在新浪微博PHP架构师的一片博文,介绍了100的信息;详见在使用curl做POST的时候, 当要POST的数据大于1024字节的时候, curl并不会直接就发起POST请求, 而是会分为俩步,; 流程如下: 1. 发送一个请求, 包含一个Expect:100-continue, 询问Server使用愿意接受数据 2. 接收到Server返回的100-continue应答以后, 才把数据POST给Server 使用libcurl的时候会碰到这样的问题; 在w3c的官网介绍看到如下一段话: 8.2.3 Use of the 100 (Continue) Status The purpose of the 100 (Continue) status (see section 10.1.1) is to allow a client that is sending a request message with a request body to determine if the origin server is willing to accept the request (based on the request headers) before the client sends the request body. In some cases, it might either be inappropriate or highly inefficient for the client to send the body if the server will reject the message without looking at the body. Requirements for HTTP/1.1 clients: – If a client will wait for a 100 (Continue) response before sending the request body, it MUST send an Expect request-header field (section 14.20) with the “100-continue” expectation. – A client MUST NOT send an Expect request-header field (section 14.20) with the “100-continue” expectation if it does not intend to send a request body. 简单翻译一下: 使用100(不中断,继续)状态码的目的是为了在客户端发出请求体之前,让服务器根据客户端发出的请求信息(根据请求的头信息)来决定是否愿意接受来自客户端的包含了请求内容的请求;在某些情况下,在有些情况下,如果服务器拒绝查看消息主体,这时客户端发送消息主体是不合适的或会降低效率 对HTTP/1.1客户端的要求: -如果客户端在发送请求体之前,想等待服务器返回100状态码,那么客户端必须要发送一个Expect请求头信息,即:”100-continue”请求头信息; -如果一个客户端不打算发送请求体的时候,一定不要使用“100-continue”发送Expect的请求头信息;
HTTP/1.1 100 Continue
最新推荐文章于 2024-06-07 12:52:18 发布