我有一个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();
我试过对邮箱地址进行UrlEncode,但没有成功.如有任何建议,我们将不胜感激.