C#尝试下载网站源,但远程服务器返回400

时间:2018-12-12 15:19:16

标签: c# .net

但是我搜索了多少却无法正常工作,我正在尝试下载https://soundcloud.com/源,但始终收到错误请求错误。我认为提供URL的方式不是问题,因为它可以与https://www.google.comhttps://twitter.com/和reddit等其他网站一起使用。

using System;
using System.Net;
using System.IO;

class PageDownloader
{   
    static void Main(string[] args) {
        string site = "";
        string savedFile = $"\\Page.html";
        string desktopPath = Environment.GetFolderPath(System.Environment.SpecialFolder.DesktopDirectory);

        Console.WriteLine("Downloading Website Source...");

        WebClient client = new WebClient();
        client.Encoding = System.Text.Encoding.UTF8;
        try {
        site = client.DownloadString("https://soundcloud.com/");
        } catch (WebException e) {
            Console.WriteLine(e.Message);
        }
        File.WriteAllText(desktopPath+savedFile, site);
        Console.WriteLine("\nDownload finished!");

        Console.ReadKey();
    }
}

我是否有任何特定原因导致我无法下载soundclouds源代码或我的代码有错误

0 个答案:

没有答案