c# - 通过API下载soundcloud数据

标签 c# windows-phone-8.1 windows-phone

我尝试通过他们的 API 从 soundcloud 检索 mp3 数据,我已经有了 download_url 属性,我想将它直接保存到 KnownFolders.MusicLibrary。 问题是当我尝试使用浏览器下载它时,链接要求保存/播放。 我是否可以绕过这个并获得直接下载链接而不必提示选择保存或播放。

最佳答案

我自己还没有尝试过,但是“download_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;
    }
}

关于c# - 通过API下载soundcloud数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32650229/

相关文章:

c# - 使用 asp.net 将 aspx 动态页面 url 转换为用户友好的 url 的最佳方法

c# - 如何在 Winforms ListView 中获取资源管理器右键单击菜单?

c# - pushChannel 在 Windows Phone 8.1 设备中始终为空(推送通知)

c++ - 我们可以使用c来开发Windows Phone 7.5应用程序吗?

windows-phone - 如何与您的 WP7 应用程序的用户取得联系?

c# - 如何转换字符串数据:audio/ogg;base64 to file wav in C#

c# - 将外部 javascript 文件视为 Aspx 页面的一部分

c# - Win RT - 带条码扫描仪的通用应用程序

c# - 将字符串转换为控件名称 c# wp8.1

windows - 如何使用复选框单击将文本 block 中的文本从大写转换为小写?