我有一个WebApi控制器,其中一个方法看起来像这样:
[HttpGet]
[AcceptVerbs("GET")]
public HttpResponseMessage Run(string reportName, int someId, string someText, DateTime asOfDate, string username)
我有一个专门为此操作配置的自定义路由。当我在浏览器中导航到Web服务时,一切都正常,并执行适当的操作:
http://localhost:xxxx/ControllerName/Run/asdf/1/asdf/07-01-2012/user@domain.com
然而,当我尝试使用HttpClient程序化调用Web服务并执行"Get"时,如果用户名参数是电子邮件地址,我会收到404错误。例如,当用户名只是"user"时,一切正常。以下是示例代码:
var url = "http://localhost:xxxx/ControllerName/Run/asdf/1/asdf/07-01-2012/user@domain.com"
var client = new System.Net.Http.HttpClient();
var response = client.Get(url);
//fails here with 404 error
response.EnsureSuccessStatusCode();
我尝试使用UrlEncoding对电子邮件地址进行编码,但没有成功。感谢任何建议。
POST
动词并发送自定义复杂对象。这样,您还可以跳过其他一些问题,例如无法在任何字符串中传递字符/
。 - user1908061https://localhost:xxxx/user@domain.com
不起作用。https://localhost:xxxx/user@domain.com/
起作用。