【问题标题】:How to add an artist's name to and endpoint with Spotify API?如何使用 Spotify API 将艺术家的姓名添加到端点?
【发布时间】:2016-09-02 21:20:59
【问题描述】:

我正在编写一个基本页面来搜索艺术家的姓名,但我在使用端点时遇到了问题。我可以将搜索粘贴到我的浏览器中,它工作正常。但是,当我运行我的程序时,它似乎并没有从 URL 中提取查询。应该和我想的一模一样吧?

@{
    var message = "...";
    var name = Request.QueryString["query"];
    if (name != null)
    {
        string search = "https://api.spotify.com/v1/search?q=" + name + "&type=artist";
        var request = (HttpWebRequest)WebRequest.Create(search);
        request.Method = "GET";

        string output = String.Empty;
        using (var response = request.GetResponse())
        {
            using (var stream = new StreamReader(response.GetResponseStream()))
            {
                output = stream.ReadToEnd();
            }
        }
        message = output;
    }
}

<!DOCTYPE html>
<html>
    <head>
        <title>Task Two</title>
    </head>
<body>
    <h1>Search for an Artist:</h1>
    <form>
        <input type="text" id="query"/>
        <input type="submit" id="search"/>
    </form>
    <p>@message</p>
</body>
</html>

【问题讨论】:

  • 能否在您的问题中包含错误响应消息?
  • 请发布您的错误代码,这将有助于处理您的问题

标签: c# asp.net razor spotify


【解决方案1】:

关闭,但您必须为输入指定 'name' 属性而不是 'id':

<form>
    <input type="text" name="query"  />
    <input type="submit" name="search" />
</form>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-07-04
    • 1970-01-01
    • 2018-05-11
    • 2015-01-30
    相关资源
    最近更新 更多