20 Jan 11Expect:100-continue

  • 作者:Laruence()
  • 本文地址:http://www.laruence.com/2011/01/20/1840.html
  • 转载请注明出处

在使用curl做POST的时候, 当要POST的数据大于1024字节的时候, curl并不会直接就发起POST请求, 而是会分为俩步,

<ol style="line-height: 21px; margin: 0px; padding: 0px; border: 0px; font-style: inherit; font-family: inherit; vertical-align: baseline; list-style-type: none;"><li style="margin: 0px; padding: 0px; border: 0px; font-style: inherit; font-family: inherit; vertical-align: baseline;">1. 发送一个请求, 包含一个Expect:100-continue, 询问Server使用愿意接受数据</li><li style="margin: 0px; padding: 0px; border: 0px; font-style: inherit; font-family: inherit; vertical-align: baseline;">2. 接收到Server返回的100-continue应答以后, 才把数据POST给Server</li><li style="margin: 0px; padding: 0px; border: 0px; font-style: inherit; font-family: inherit; vertical-align: baseline;"></li></ol>

这是libcurl的行为.

具体的RFC相关描述:http://www.w3.org/Protocols/rfc2616/rfc2616-sec8.html#sec8.2.3

于是,这样就有了一个问题, 并不是所有的Server都会正确应答100-continue, 比如lighttpd, 就会返回417 “Expectation Failed”, 则会造成逻辑出错,,

要解决的办法也挺容易:

<ol style="line-height: 21px; margin: 0px; padding: 0px; border: 0px; font-style: inherit; font-family: inherit; vertical-align: baseline; list-style-type: none;"><li style="margin: 0px; padding: 0px; border: 0px; font-style: inherit; font-family: inherit; vertical-align: baseline;"><span style="margin: 0px; padding: 0px; border: 0px; font-family: inherit; vertical-align: baseline; color: rgb(255, 210, 167);">curl_setopt</span><span style="margin: 0px; padding: 0px; border: 0px; font-style: inherit; font-family: inherit; vertical-align: baseline;">(</span><span style="margin: 0px; padding: 0px; border: 0px; font-family: inherit; vertical-align: baseline; color: rgb(198, 197, 254);">$ch</span><span style="margin: 0px; padding: 0px; border: 0px; font-style: inherit; font-family: inherit; vertical-align: baseline;">,</span> CURLOPT_HTTPHEADER<span style="margin: 0px; padding: 0px; border: 0px; font-style: inherit; font-family: inherit; vertical-align: baseline;">,</span> <span style="margin: 0px; padding: 0px; border: 0px; font-family: inherit; vertical-align: baseline; color: rgb(150, 203, 254);">array</span><span style="margin: 0px; padding: 0px; border: 0px; font-style: inherit; font-family: inherit; vertical-align: baseline;">(</span><span style="margin: 0px; padding: 0px; border: 0px; font-family: inherit; vertical-align: baseline; color: rgb(168, 255, 96);">'Expect:'</span><span style="margin: 0px; padding: 0px; border: 0px; font-style: inherit; font-family: inherit; vertical-align: baseline;">));</span></li><li style="margin: 0px; padding: 0px; border: 0px; font-style: inherit; font-family: inherit; vertical-align: baseline;"><span style="margin: 0px; padding: 0px; border: 0px; font-family: inherit; vertical-align: baseline; color: rgb(124, 124, 124);">// Disable Expect: header (lighttpd does not support it)</span></li></ol>

更多相关文章

  1. PHPExcel导入导出及大量数据导入缓存方式的修改
  2. 无法从Ajax POST请求中将带空格的数据导入数据库
  3. php写app接口并返回json数据
  4. MySQL错误1046:未选择数据库
  5. 社交登录实现的数据库结构?
  6. Json调用JSON.parse:意外结束数据
  7. Symfony2 -从数据库中提取数据并以表单形式显示
  8. PHP接收到的$_POST数据里的邮箱符号@变成了%40
  9. Mysql使用高流量数据库上的过滤器计算行数

随机推荐

  1. thinkphp整合系列之tcpdf类生成pdf文件
  2. php中global的作用
  3. 要求PIN使用Symfony2登录
  4. PHP中是否存在“clamp”数字函数?
  5. php评论回复无限极嵌套如何实现?已写基本
  6. 短期项目求PHP开发人员或开发团队(2-3名),并
  7. 如何将JSON传回PHP的AJAX请求?
  8. PHP限制HTML内容中图片必须是本站的方法
  9. php网站 手机归属地查询接口
  10. PHP日期添加1年到当前日期。