C# 如何将URI保存到文件

C# 如何将URI保存到文件,c#,unity3d,uwp,hololens,C#,Unity3d,Uwp,Hololens,我正在尝试将MRC视频从Hololens传输到我的电脑;有一个,但将URI播放到媒体播放器,我正在尝试将其保存到文件中。我该怎么做?我已经尝试过使用HttpClient,但是当我向URI发送请求时,应用程序似乎崩溃了。在我附加的链接中,有一个StartPlayback()方法,它将媒体播放器的源属性设置为URI,并且似乎工作正常。我试图用以下方式修改它: private async void StartPlayback() { Uri link = new Uri(str

我正在尝试将MRC视频从Hololens传输到我的电脑;有一个,但将URI播放到媒体播放器,我正在尝试将其保存到文件中。我该怎么做?我已经尝试过使用HttpClient,但是当我向URI发送请求时,应用程序似乎崩溃了。在我附加的链接中,有一个StartPlayback()方法,它将媒体播放器的源属性设置为URI,并且似乎工作正常。我试图用以下方式修改它:

private async void StartPlayback()
    {
        Uri link = new Uri(string.Format("mrvc://{0}:{1}", this.txAddress.Text, this.txPort.Text));
        this.videoPlayer.Source = link;
        using (var client = new HttpClient())
        using (var response = await client.GetAsync(link))
        {
            // make sure our request was successful
            response.EnsureSuccessStatusCode();

            // read the filename from the Content-Disposition header
            var filename = response.Content.Headers.ContentDisposition.FileName;

            // read the downloaded file data
            var stream = await response.Content.ReadAsStreamAsync();

            // Where you want the file to be saved
            var destinationFile = Path.Combine("C:\\Users\\orsteam\\Documents", filename);

            // write the steam content into a file
            using (var fileStream = File.Create(destinationFile))
            {
                stream.CopyTo(fileStream);
            }
        }
        this.bnStart.IsEnabled = false;
        this.bnStop.IsEnabled = true;
    }

谢谢大家!

在Unity中,您没有访问HttpClient的权限。您可以更改为使用该类。
记得检查
Internet客户端的功能。

您的代码有问题吗?我一直在System.Net.Http.dll中遇到“异常抛出:'System.ArgumentException'”—即使我注释掉响应块,它也会崩溃,所以问题似乎来自Wait Client.getAsync(链接)抱歉,我认为你在Unity中成功是因为你添加了标签。