Search code examples
cratedb

CrateDB cannot connect in HttpEndpoint to remote secure server


I've been testing crateDB 3.3.4 for a few weeks now, and I've always been connecting through localhost (127.0.0.1) in http. I've been bulk importing data with HttpEndpoint on my localhost successfully.

I'm now testing on a cloud cluster in https. I manage to open Chrome and logon on the server, but I cannot manage to remote in C# via HttpEndpoint.

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;

When I try the following code, I always get "The underlying connection was closed: An unexpected error occurred on a send." and in the exception, I see "Unable to write data to the transport connection: An existing connection was forcibly closed by the remote host."

Any Idea what I'm doing wrong here? I was doing the same thing before, on my localhost, but without specifying credentials, and it was working great.


Solution

  • Assuming from your code sample you are using password authentication. Permanent solution would indeed be using autorization header.

    As described here https://crate.io/docs/crate/reference/en/latest/admin/auth/methods.html#password-authentication-method