的WebAPI方法,电子邮件地址,参数从HttpClient的返回404 [英] WebApi method with email address parameter returns 404 from HttpClient
问题描述
我有看起来像这种方法的WebAPI控制器:
I have a WebApi controller with a method that looks like such:
[HttpGet]
[AcceptVerbs("GET")]
public HttpResponseMessage Run(string reportName, int someId, string someText, DateTime asOfDate, string username)
我有专门针对此操作配置的自定义路线。当我浏览我的浏览器的Web服务,一切工作正常,并执行相应的操作:
I have a custom route configured specifically for this action. When I navigate my browser to the web service, everything works fine, and the appropriate action is executed:
http://localhost:xxxx/ControllerName/Run/asdf/1/asdf/07-01-2012/user@domain.com
然而,当我尝试使用的HttpClient和执行编程调用Web服务的获取我得到一个404错误。当用户名参数不是一个电子邮件地址,我没有得到一个错误。例如,当用户名就是用户一切工作正常。下面是示例code:
However, when I attempt to programatically call the web service using the HttpClient and executing a "Get" I get a 404 error. I don't get an error when the username parameter is not an email address. For example, when the username is just "user" everything works fine. Here is the sample code:
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();
我都试过,没有运气URL编码的电子邮件地址。任何的建议是AP preciated。
I have tried UrlEncoding the email address with no luck. Any advice is appreciated.
推荐答案
只是快速的想法...可以在.COM是导致该问题的?
Just a quick thought... could the ".com" be causing the issue?
这篇关于的WebAPI方法,电子邮件地址,参数从HttpClient的返回404的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!