think-worker icon indicating copy to clipboard operation
think-worker copied to clipboard

tp5.1使用workerman作为HttpServer运行时,用postman等访问异常

Open 123shang60 opened this issue 4 years ago • 2 comments

使用composer新建tp5.1项目并按照 https://www.kancloud.cn/manual/thinkphp5_1/354134 安装workerman,并能够使用命令正常启动。 启动后,使用浏览器能够正常看到tp5.1首页,但是换用postman、cURL等工具访问测试接口时,无论使用何种请求都会失败。 使用平台为win10,PHP版本7.4 若将浏览器中的请求复制到powershell中执行,则会报告如下错误: Invoke-WebRequest : 服务器提交了协议冲突. Section=ResponseStatusLine 所在位置 行:1 字符: 1

  • Invoke-WebRequest -Uri "http://127.0.0.1:8088/" -Headers @{
  •   + CategoryInfo          : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-WebRequest],WebExce
      ption
      + FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeWebRequestCommand
    
    

复制的命令为: Invoke-WebRequest -Uri "http://127.0.0.1:8088/" -Headers @{ "Cache-Control"="max-age=0" "Upgrade-Insecure-Requests"="1" "User-Agent"="Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.113 Safari/537.36 Edg/81.0.416.58" "Accept"="text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,/;q=0.8,application/signed-exchange;v=b3;q=0.9" "Sec-Fetch-Site"="none" "Sec-Fetch-Mode"="navigate" "Sec-Fetch-User"="?1" "Sec-Fetch-Dest"="document" "Accept-Encoding"="gzip, deflate, br" "Accept-Language"="zh-CN,zh;q=0.9,en;q=0.8,en-GB;q=0.7,en-US;q=0.6" "Cookie"="PHPSESSID=c66be331f3a7d74120d6b1a4" }

123shang60 avatar Apr 22 '20 04:04 123shang60

经过试验,在使用2.0分支下的top-think/think-worker时,修改两处即可有效缓解这个问题: 1)在Application.php文件下70行后增加$connection->close(); 2)删除Application.php文件内82行的代码

123shang60 avatar Apr 22 '20 07:04 123shang60

还望检查一下代码,在thinkphp5.1.x+top-think/think-worker2.0.x的组和下,使用curl访问会提示: curl: (1) Unsupported HTTP version in response

123shang60 avatar Apr 22 '20 07:04 123shang60