使用cURL的HTTP GET提供SSL错误 [英] HTTP GET using cURL is giving SSL error

查看:120
本文介绍了使用cURL的HTTP GET提供SSL错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经编写了一个REST服务器,该服务器侦听端口8000.我试图使用cURL命令从同一台计算机上调用api-

I have written a REST server which listens on port 8000. I am trying to invoke the api from the same machine using the cURL command -

curl -H "accept: application/json" https://localhost:8000/status -v

我遇到以下错误

* About to connect() to localhost port 8000 (#0)
*   Trying ::1...
* Connected to localhost (::1) port 8000 (#0)
* Initializing NSS with certpath: sql:/etc/pki/nssdb
*   CAfile: /etc/pki/tls/certs/ca-bundle.crt
  CApath: none
* NSS error -12263 (SSL_ERROR_RX_RECORD_TOO_LONG)
* SSL received a record that exceeded the maximum permissible length.
* Closing connection 0
curl: (35) SSL received a record that exceeded the maximum permissible length.

我尝试使用-k选项绕过证书验证,但无济于事.我在这里想念什么?如果需要更多信息,请发表评论.

I have tried bypassing the certificate verification using -k option but to no avail. What am I missing here? Please comment if any more info is required.

编辑:我的朋友建议在cURL命令中仅尝试使用http.然后,它绕过了SSL检查,并且可以正常工作.但是https怎么了?我还需要为本地主机安装证书吗?另外,为什么-k选项不起作用?

EDIT: My friend suggested to try with only http in the cURL command. Then it bypassed SSL check and it worked. But whats going wrong with https? Do I need to install certificate for localhost also? Also, why didn't -k option work?

推荐答案

我的朋友建议在cURL命令中仅尝试使用http.然后,它绕过了SSL检查,并且可以正常工作.

My friend suggested to try with only http in the cURL command. Then it bypassed SSL check and it worked.

您的服务器似乎根本没有启用SSL.这就是为什么HTTP有效而HTTPS无效的原因.使用HTTP不会绕过任何SSL检查,因为没有带HTTP的SSL,因此也没有绕过SSL的检查.

It looks like that your server has not SSL enabled at all. That's why HTTP worked and HTTPS did not. Using HTTP did not bypass any SSL check because there is no SSL with HTTP and thus no SSL check to bypass.

此外,为什么-k选项不起作用?

Also, why didn't -k option work?

-k 选项用于跳过SSL(HTTPS)连接上的证书验证.但是,仅当首先存在SSL连接时,它才可以工作.由于您的服务器根本不支持SSL,因此 -k 将无济于事.

The -k option is used to skip certificate validation on SSL (HTTPS) connections. But it can only work if there is a SSL connection in the first place. Since your server does not support SSL at all -k will not help.

我还需要为本地主机安装证书吗?

Do I need to install certificate for localhost also?

您需要首先在(未知)服务器上启用SSL.如果您对自己的服务器进行了编码,则意味着需要进行其他编码.而且,一旦服务器完全可以执行SSL,您还需要设置服务器可以提供给客户端的证书.

You need to first enable SSL on your (unknown) server. If your coded your own server then this means additional coding. And, once the server can do SSL at all you also need to setup a certificate which the server can provide to the client.

这篇关于使用cURL的HTTP GET提供SSL错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆