実現したいこと
C#のBlazorを使用して、URLからそのページのソースコードを取得出来るようにする。
前提
ここに質問の内容を詳しく書いてください。
Blazorを使って、URLからソースコードを取得するプログラムを作成していますが、
ソースコードを取得するボタンをクリックするとエラーメッセージがブラウザ上に表示されます。
解決方法が分かる方はご教示お願いします。
発生している問題・エラーメッセージ
「An unhandled error has occurred.」
該当のソースコード
@page "/" @using System.Runtime.InteropServices; <h3>Fetch Source Code</h3> <p> <label for="urlInput">URL:</label> <input type="text" id="urlInput" @bind="@url" /> </p> <button @onclick="FetchSourceCode">Fetch</button> @if (!string.IsNullOrEmpty(sourceCode)) { <pre>@sourceCode</pre> } @code { private string url; private string sourceCode; private async Task FetchSourceCode() { if (!string.IsNullOrEmpty(url)) { using (HttpClient client = new HttpClient()) { sourceCode = await client.GetStringAsync(url); } } } }
ボールドテキスト

バッドをするには、ログインかつ
こちらの条件を満たす必要があります。