HTTP/1.1协议的curl 返回 HTTP/1.1 100 Continue 加上header 加上body

29 篇文章 0 订阅
使用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的请求头信息;
  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
HTTP/1.1 502 Bad Gateway是一种服务器错误响应状态码,表示作为网关或代理服务器的上游服务器收到了无效的响应。出现这个错误通常是因为上游服务器出现故障或配置错误。为了解决这个问题,有几种方法可以尝试: 1. 检查上游服务器:首先,确认上游服务器是否正常工作。可以尝试通过浏览器或其他方法直接访问该服务器来检查是否能够正常响应。如果服务器没有问题,那么可能是其他原因导致了502错误。 2. 检查网络连接:确保网络连接没有问题。检查网络连接是否稳定,并且没有任何阻止或限制网络流量的问题。可以尝试使用其他网络连接来验证问题是否与特定网络有关。 3. 重启服务:尝试重启相关的服务,例如php-fpm。通过重启服务,可以清除临时的状态或错误,从而解决502错误。 4. 检查代码:如果问题是由于代码中的错误导致的,可以检查代码并修复错误。确保代码没有任何语法错误或逻辑错误,这可能导致与上游服务器的通信出现问题。 5. 联系服务器管理员:如果以上方法都无法解决问题,建议联系服务器管理员或技术支持团队寻求帮助。他们可能会提供更具体的指导或解决方案,以解决502错误。 需要注意的是,每个情况可能有不同的解决方法,具体的解决方法取决于问题的原因和环境的配置。因此,建议根据实际情况选择合适的方法来解决502错误。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* [file_get_contents() 报错failed to open stream: HTTP request ... HTTP/1.1 505 HTTP Version Not Supp](https://blog.csdn.net/weixin_43944691/article/details/113727198)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 33.333333333333336%"] - *2* [Nginx 遇到502 Bad Gateway 自动重启的脚本代码](https://download.csdn.net/download/weixin_38704386/14892644)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 33.333333333333336%"] - *3* [php程序出现 502 bad gateway 的分析流程](https://blog.csdn.net/weixin_35993148/article/details/116040333)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 33.333333333333336%"] [ .reference_list ]

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值