我正在编写一个基本页面来搜索艺术家的名字,但我在使用端点时遇到了问题。我可以将搜索粘贴到我的浏览器中,它运行良好。但是,当我运行我的程序时,它似乎并没有从 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>
最佳答案
关闭,但您必须为输入指定“name”属性而不是“id”:
<form>
<input type="text" name="query" />
<input type="submit" name="search" />
</form>
关于c# - 如何使用 Spotify API 将艺术家的名字添加到端点?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37095461/