我正在尝试使用RestSharp在显然没有有效ssl证书的服务器上启动REST请求,因为我收到错误
基础连接已关闭:无法建立信任 SSL / TLS安全通道的关系。
我找到了this question,但提供的解决方案虽然看起来很简单,但仍然无法解决。这是我的代码,任何想法可能是错的?
private void Test_REST()
{
var client = new RestClient("https://online.gema.de");
// both versions not working
ServicePointManager.ServerCertificateValidationCallback += (sender, certificate, chain, sslPolicyErrors) => true;
client.RemoteCertificateValidationCallback += (sender, certificate, chain, sslPolicyErrors) => true;
// execute the request
IRestResponse response = client.Execute(GEMA_Authorize());
var content = response.Content; // raw content as string
}
private RestRequest GEMA_Authorize()
{
RestRequest request = new RestRequest("api/v1/authorize", Method.GET);
request.AddParameter("response_type", "token");
request.AddParameter("client_id", "test_client");
request.AddHeader("Accept", "application/json");
request.AddHeader("Content-Type", "application/x-www-form-urlencoded");
return request;
}
当我像这样写回调时:
.ServerCertificateValidationCallback += (sender, certificate, chain, sslPolicyErrors) =>
{
return true;
};
并在return true;
处设置断点,执行不会停在那里,因此似乎永远不会回调回调。任何想法可能是什么问题?我对REST很新,所以我可能会错过一些至关重要的东西。
提前致谢,
弗兰克
答案 0 :(得分:0)
的用法
fill_perc <- function(x, groups, prob, values){
stopifnot(length(prob) == length(values))
prob <- prob/sum(prob)
i <- which(is.na(x))
j <- sample(length(values), size = length(i), prob = prob, replace = TRUE)
x[i] <- values[j]
groups[i] <- names(values)[j]
list(x = x, groups = groups)
}
P <- c(11.8, 38, 50)
V <- setNames(c(29.5, 59.35, 97), c("Spat", "Small", "Market"))
set.seed(2020)
fill_perc(Length, size, P, V)
#$x
# [1] 81.00 66.00 44.00 59.35 29.00 24.00 68.00 97.00 92.00 21.00
#[11] 28.00 25.00 59.35 97.00 34.00 91.00 97.00 65.00 58.00 110.00
#[21] 52.00 48.00 96.00 95.00 54.00 40.00 98.00 63.00 138.00 30.00
#[31] 110.00
#
#$groups
# [1] "Market" "Small" "Small" "Small" "Spat" "Spat" "Small" "Market"
# [9] "Market" "Spat" "Spat" "Spat" "Small" "Market" "Spat" "Market"
#[17] "Market" "Small" "Small" "Market" "Small" "Small" "Market" "Market"
#[25] "Small" "Small" "Market" "Small" "Market" "Spat" "Market"
为我工作。