问题描述
我试图用R. HTTP POST方法来从我的服务器JSON数组
I'm trying to fetch a JSON array from my server using the HTTP POST method in R.
我同时使用 POST
函数试图从 HTTR
和的getURL
从 RCurl 但都返回错误。
I've tried using both the
POST
function from httr
and the getURL
function from RCurl
but both return errors.
cafile <- system.file("CurlSSL", "cacert.pem", package = "RCurl")
url <- "https://example.com/query/getData.php"
POST(url,body=NULL)
POST(url,body=NULL,config(cainfo=cafile))
getURL(url)
getURL(url,cainfo=cafile)
在
POST
函数给出错误的是(两个电话):
The error given by the
POST
function is (for both calls):
Error in curl::curl_fetch_memory(url, handle = handle) :
SSL peer certificate or SSH remote key was not OK
在
的getURL
函数给出错误的是(没有配置(cainfo =凭证档案错误)
):
The error given by the
getURL
function is (without config(cainfo=cafile)
):
* Hostname was NOT found in DNS cache
* Trying 162.xxx.xxx.xxx...
* connect to 162.xxx.xxx.xxx port 443 failed: Connection refused
* Trying 130.yyy.yyy.yyy...
* Connected to example.com (130.yyy.yyy.yyy) port 443 (#0)
* found 175 certificates in /etc/ssl/certs/ca-certificates.crt
* gnutls_handshake() warning: The server name sent was not recognized
* failed to get server cert
* Closing connection 0
Error in function (type, msg, asError = TRUE) :
gnutls_handshake() warning: The server name sent was not recognized
我怀疑这事做有R自运行:
I'm suspecting this has something to do with R since running:
curl 'https://example.com/query/getData.php'
在命令行返回预期的结果。
from the command line return the expected result.
服务器与COMODO SSL证书的Apache2服务器。
在 /etc/apache2/sites-enabled/000-default.conf
服务器名称设置为
The server is a apache2 server with COMODO SSL certificate.In
/etc/apache2/sites-enabled/000-default.conf
the server name is set to
ServerName www.example.com
任何帮助将是一个最preciated
Any help would be most apreciated
推荐答案
的
HTTR
套餐包括它自己的CA束所以这可能不是问题。更有可能的是一个服务器端的配置SNI问题或与您的证书有问题
The
httr
package includes it's own CA bundle so this probably not the issue. More likely a server side SNI config problem or a problem with your certificate
不幸的是你有没有贴有一个实际的URL重复的例子。但随着新OpenSSL软件包的最新版本,你可以轻松地调试您的服务器证书:
Unfortunately you haven't posted a reproducible example with an actual URL. But with the latest version of the new openssl package you can easily debug your server cert:
library(openssl)
cert <- download_ssl_cert("www.r-project.org")
print(cert)
print(as.list(cert[[1]]))
也可以尝试验证它
Also try validating it
verify_cert(cert, ca_bundle())
这可能会给上有什么错你的证书的提示。
This might give a hint on what's wrong with your certificate.
这篇关于获得通过SSL的网站内容与R中HTTR的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!