【发布时间】:2021-11-29 05:18:58
【问题描述】:
-
使用语言:C#
-
输入:缩写或表情符号。
-
输出:缩写或表情符号的翻译
-
代码:
公共类 EmoticonController : ApiController { // GET: api/表情/缩写/简写 [HttpGet] [Route("api/表情/缩写/{shortform}")]
public string Abbreviation(string ShortForm) { string outputMessage; // Switch case that assigns the outputMessage the translation to the abbreviation entered by the user switch (ShortForm) { case "TY": outputMessage = "Thank you"; break; case "(~.~)": outputMessage = "sleepy"; break; default: outputMessage = "Invalid Input"; break; } return outputMessage; }
}
我在Visual Studio中运行上面的代码,输入网址为
localhost/api/表情/缩写/(~.~)
我收到以下错误: C# URL Special characters error
PS:截图 URL 确实与我提到的代码不同。请忽略这一点。我修复了它,但错误仍然存在。
【问题讨论】:
-
在截图中请求的 url 不同
-
URI 中允许的字符是有限的。如果您需要使用特殊字符(如您所做的那样),您应该对它们进行编码。见stackoverflow.com/questions/1856785/characters-allowed-in-a-url、stackoverflow.com/questions/575440/url-encoding-using-c-sharp、stackoverflow.com/questions/44920875/…
标签: c# windows visual-studio