本文へスキップ
ecdsa.com
.NET SslStream / HttpClient.NET

エラーメッセージ

Cannot determine the frame size or a corrupted frame was received.

別の表記

  • System.Security.Authentication.AuthenticationException: Cannot determine the frame size or a corrupted frame was received.

.NET Core、.NET 5〜10、.NET Framework で同じテキストです。HttpClient はこれを「The SSL connection could not be established, see inner exception.」でラップします。

.NET SslStream / HttpClient — AuthenticationException when the peer's reply is not a TLS record

このエラーの意味

SslStream は TLS レコードヘッダーを想定していましたが、ヘッダーの形になっていないバイト列を受け取ったため、次のフレームの長さすら判断できません。相手はそのポートで TLS を使って通信していません。典型的なのは、平文 HTTP のエンドポイント(「HTTP/1.1 400 …」)に https:// で接続した場合や、平文で始まるプロトコルの場合です。

発生する理由

修正方法

  1. 1.

    ポートが何のプロトコルで応答するかを確認する

    平文 HTTP で応答がある場合は、HTTPS のポートを使うか、http:// を使ってください。

    bash
    curl -si http://api.example.com:8080/ | head -1    # answers over plain HTTP?
  2. 2.

    Kestrel が待ち受けている HTTPS の URL を使う

    applicationUrl または ASPNETCORE_URLS を確認し、https:// のアドレスをそのポート番号付きで呼び出してください。

    json
    {
      "profiles": {
        "https": {
          "commandName": "Project",
          "applicationUrl": "https://localhost:7001;http://localhost:5001"
        }
      }
    }
  3. 3.

    メール:STARTTLS のポートには STARTTLS が必要

    MailKit では、587 番ポートには SecureSocketOptions.StartTls を使い、SslOnConnect は 465 番ポートでのみ使ってください。

    csharp
    // MailKit: STARTTLS on 587, implicit TLS (SslOnConnect) on 465
    await smtp.ConnectAsync("mail.example.com", 587, MailKit.Security.SecureSocketOptions.StartTls);

関連するエラー

署名エラーデータベースをすべて見る