Vla*_*iev 6 swagger swagger-ui openapi
Swagger UI 拒绝使用自签名证书向https发出请求。
接下来的问题是:
curl -X POST "https://localhost:8088/Authenticate" -H "accept: pplication/json" -H "Content-Type: application/json" -d "{ \"username\":"user\", \"password\": \"user\"}"
Run Code Online (Sandbox Code Playgroud)
以上命令由 swagger 自动生成,运行后返回:
TypeError: Failed to fetch
Run Code Online (Sandbox Code Playgroud)
手动(不使用 Swagger UI)运行返回:
curl: (60) SSL certificate problem: self signed certificate
More details here: https://curl.haxx.se/docs/sslcerts.html
curl failed to verify the legitimacy of the server and therefore could not
establish a secure connection to it. To learn more about this situation and
how to fix it, please visit the web page mentioned above.
Run Code Online (Sandbox Code Playgroud)
我想让它像下一个(添加--insecure参数):
curl -X POST "https://localhost:8088/Authenticate" -H "accept: application/json" -H "Content-Type: application/json" -d "{ \"username\": \"user\", \"password\": \"user\"}" --insecure
Run Code Online (Sandbox Code Playgroud)
这将允许我执行所需的请求。有没有办法向自动生成的 Swagger curl 添加自定义参数?谢谢。
首先,cURL 命令仅用于显示和复制粘贴。Swagger UI 实际上并不使用 cURL 来处理请求——它是一个网页,所以它使用 JavaScript(fetch API或XMLHttpRequest或类似的)发出请求。
正如解释在这里,扬鞭UI不支持自签名证书(重点煤矿):
您的证书似乎有问题。出于我们无法控制的安全原因,Swagger-UI(或任何浏览器内的应用程序)无法绕过浏览器内置的证书验证过程。
看起来您有一个自签名证书。您需要研究如何让您的计算机信任您的证书,这里是 Google Chrome 的指南,您似乎正在使用它:
因此,如果您想使用 Swagger UI 测试使用自签名证书的服务器,则需要将浏览器(或计算机)配置为信任该证书。查看这些问题以获取建议:
Chrome: 让 Chrome 接受自签名的本地主机证书
Firefox: 有没有办法让 Firefox 忽略无效的 ssl 证书?
有没有办法向自动生成的 Swagger curl 添加自定义参数?
生成 cURL 命令的代码在这里:https :
//github.com/swagger-api/swagger-ui/blob/master/src/core/curlify.js
您可以分叉 Swagger UI 并根据需要调整代码。
但如上所述 - 更改显示的 cURL 命令不会更改实际的“试用”行为,因为“试用”无法绕过证书验证。
| 归档时间: |
|
| 查看次数: |
10893 次 |
| 最近记录: |