我尝试通过他们的 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/