【トラブル】【C#】 ネットワーク / 証明書関連のトラブル

■ はじめに

https://blogs.yahoo.co.jp/dk521123/36987774.html
の実装中に起こったエラーに対して、トラブルシュートした時の記録。

■ 例外「(407) Proxy Authentication Required」が発生する

エラー内容

System.Net.WebException:
The remote server returned an error: (407) Proxy Authentication Required

原因

 * プロキシサーバで、ユーザ認証を設定しているが、その対応ができなかったため

対応策

HttpWebRequest request = (HttpWebRequest)WebRequest.Create("https://yahoo.co.jp");
// ★この部分★ Proxyサーバ・ユーザ認証を使用している場合 
request.Proxy.Credentials = new NetworkCredential("user_name", "password");
using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())

■ 例外「Could not establish trust relationship for the SSL/TLS secure channel」が発生する

エラー内容

System.Net.WebException:
The underlying connection was closed:
Could not establish trust relationship for the SSL/TLS secure channel.

原因

 * SSL証明書がインポートされていなかったため

対応策

 * SSL証明書がインポートする

関連記事

C#】 レスポンスから証明書を作成する

https://blogs.yahoo.co.jp/dk521123/36987774.html