Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
123shang60 opened this issue Apr 22, 2020 · 2 comments

Comments

@123shang60
Copy link

使用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
Copy link
Author

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

@123shang60
Copy link
Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant