C# 通过API下载SounClud数据

C# 通过API下载SounClud数据,c#,windows-phone-8.1,windows-phone,C#,Windows Phone 8.1,Windows Phone,我试图通过soundcloud的API从soundcloud检索mp3数据,我已经有了download_url属性,我想将其直接保存到KnownFolders.MusicLibrary。 问题是当我试图用浏览器下载时,链接“请求保存/播放”。 我是否可以绕过此选项,获得直接下载链接,而无需提示选择保存或播放。尝试使用HttpClient或WebClient。 据我所知,WebClient有一个OpenReadAsync方法 使用此方法并将mp3 url作为参数传递 您将得到一个mp3流,然后您可

我试图通过soundcloud的API从soundcloud检索mp3数据,我已经有了download_url属性,我想将其直接保存到KnownFolders.MusicLibrary。 问题是当我试图用浏览器下载时,链接“请求保存/播放”。
我是否可以绕过此选项,获得直接下载链接,而无需提示选择保存或播放。

尝试使用HttpClient或WebClient。 据我所知,WebClient有一个OpenReadAsync方法

使用此方法并将mp3 url作为参数传递


您将得到一个mp3流,然后您可以使用StreamWriter将其作为文件保存到本地文件夹。

尝试使用HttpClient或WebClient。 据我所知,WebClient有一个OpenReadAsync方法

使用此方法并将mp3 url作为参数传递


您将得到的是mp3流,然后您可以使用StreamWriter将其保存到本地文件夹中作为文件。

我自己没有尝试过,但“下载url”是您所说的原始文件的url。尝试使用此代码并查看得到的结果,然后可以修改请求,直到获得数据流。您还可以尝试使用Burp或Fiddler等代理来检查传递给Soundcloud的内容,然后创建类似的请求

public static string GetSoundCloudData()
{
    var request = (HttpWebRequest)WebRequest.Create("http://api.soundcloud.com/tracks/3/download");
    request.Method = "GET";
    request.UserAgent =
        "Mozilla/5.0 (Windows NT 6.3; WOW64; rv:38.0) Gecko/20100101 Firefox/38.0";
    // Get the response.
    WebResponse response = request.GetResponse();
    // Display the status.
    if (((HttpWebResponse)response).StatusCode == HttpStatusCode.OK)
    {
        // Get the stream containing content returned by the server.
        var dataStream = response.GetResponseStream();
        // Open the stream using a StreamReader for easy access.
        StreamReader reader = new StreamReader(dataStream, Encoding.UTF8);
        // Read the content.
        string responseFromServer = reader.ReadToEnd();
        // Display the content.
        Debug.WriteLine(responseFromServer);

        // Clean up the streams.
        reader.Close();
        dataStream.Close();
        response.Close();
        return responseFromServer;

    }
    else
    {
        response.Close();
        return null;
    }
}

我自己也没有尝试过,但“下载url”正如您所说是指向原始文件的url。尝试使用此代码并查看得到的结果,然后可以修改请求,直到获得数据流。您还可以尝试使用Burp或Fiddler等代理来检查传递给Soundcloud的内容,然后创建类似的请求

public static string GetSoundCloudData()
{
    var request = (HttpWebRequest)WebRequest.Create("http://api.soundcloud.com/tracks/3/download");
    request.Method = "GET";
    request.UserAgent =
        "Mozilla/5.0 (Windows NT 6.3; WOW64; rv:38.0) Gecko/20100101 Firefox/38.0";
    // Get the response.
    WebResponse response = request.GetResponse();
    // Display the status.
    if (((HttpWebResponse)response).StatusCode == HttpStatusCode.OK)
    {
        // Get the stream containing content returned by the server.
        var dataStream = response.GetResponseStream();
        // Open the stream using a StreamReader for easy access.
        StreamReader reader = new StreamReader(dataStream, Encoding.UTF8);
        // Read the content.
        string responseFromServer = reader.ReadToEnd();
        // Display the content.
        Debug.WriteLine(responseFromServer);

        // Clean up the streams.
        reader.Close();
        dataStream.Close();
        response.Close();
        return responseFromServer;

    }
    else
    {
        response.Close();
        return null;
    }
}

Thx@Ogglas,我使用了您的一些代码并成功地检索了cdn url:

var request = (HttpWebRequest)WebRequest.Create(url);
request.Method = "GET";
var response = await request.GetResponseAsync();
var downloadurl = response.ResponseUri.AbsoluteUri;

Thx@Ogglas,我使用了您的一些代码并成功地检索了cdn url:

var request = (HttpWebRequest)WebRequest.Create(url);
request.Method = "GET";
var response = await request.GetResponseAsync();
var downloadurl = response.ResponseUri.AbsoluteUri;

它不是直接下载文件,也不是xxx/xxx.mp3。链接是这样的:我的示例是“”,因此非常相似。试试代码,看看你得到了什么。thx dude我使用了你的一些代码,能够检索cdn url。我会把它贴在答题上。@GaneshSalim很高兴它成功了!如果您满意,您可以标记答案,这样问题将被绿色标记。它不是直接下载文件,也不是xxx/xxx.mp3。链接是这样的:我的示例是“”,因此非常相似。试试代码,看看你得到了什么。thx dude我使用了你的一些代码,能够检索cdn url。我会把它贴在答题上。@GaneshSalim很高兴它成功了!如果你满意的话,你可以标记答案,这样问题就会被绿色标记。我没有尝试过这个,但我得到了解决方案,我会尝试这个方法,看看它是否有效。谢谢你的帮助。我没有试过这个,但我找到了解决办法,我要试试这个方法,看看它是否有效。谢谢你的帮助。