CrateDB无法在HttpEndpoint中连接到远程安全服务器

时间:2019-07-04 17:27:33

标签: cratedb

我已经测试了crateDB 3.3.4几周了,并且我一直通过http中的localhost(127.0.0.1)进行连接。我已经在localhost上成功使用HttpEndpoint批量导入数据。

我现在正在使用https在云集群上进行测试。我设法打开Chrome并在服务器上登录,但是我无法通过HttpEndpoint在C#中进行远程管理。

HttpWebRequest httpWebRequest = (HttpWebRequest)WebRequest.Create("https://remoteServerUrl:4200/_sql");
      httpWebRequest.Method = "POST";
      httpWebRequest.Credentials = new NetworkCredential("username", "password");
      httpWebRequest.Timeout = 600000;
      httpWebRequest.ContentType = "application/json";

      using(var streamWriter = new StreamWriter(httpWebRequest.GetRequestStream()))
      {
        streamWriter.Write(request);
        streamWriter.Flush();
      }

      HttpWebResponse response = (HttpWebResponse)httpWebRequest.GetResponse();
      success = response.StatusCode == HttpStatusCode.OK;

当我尝试以下代码时,总是得到“底层连接已关闭:发送中发生意外错误”。并且例外,我看到“无法将数据写入传输连接:远程主机强行关闭了现有连接。”

任何主意,我在这里做错了什么?之前,我在本地主机上做过同样的事情,但是没有指定凭据,而且效果很好。

2 个答案:

答案 0 :(得分:1)

从代码示例中假设您正在使用密码身份验证。永久解决方案的确将使用autorization标头。

如此处https://crate.io/docs/crate/reference/en/latest/admin/auth/methods.html#password-authentication-method

所述

答案 1 :(得分:0)

这不是永久的解决方案,但出于测试目的,它可以工作。我通过直接在httpwebRequest中添加Authorization Header解决此问题。

f0 = 6 f1 = 1 k = 2 ft = 0.3 gfc = function(fc) { ft - ((f0 - fc) / k) + ((f1 / k) * log((fc - f1) / (f0 - f1))) } uniroot(gfc, interval = c(f0, f1)) #> $root #> [1] 5.504386 #> #> $f.root #> [1] 6.72753e-09 #> #> $iter #> [1] 5 #> #> $init.it #> [1] NA #> #> $estim.prec #> [1] 6.103516e-05

要找到要传递的身份验证令牌,只需将用户名和密码放在基本的身份验证令牌生成器中,如下所示: https://www.blitter.se/utils/basic-authentication-header-generator/

但是,如果有人有永久解决方案,我仍然想看看它是什么。

相关问题