+(加号)登录Web API路由

我正在使用asp.net web api项目,我必须通过post传递手机号码。 但我不能返回一个加号。

我的路线:

config.Routes.MapHttpRoute( name: "SmsRoute", routeTemplate: "rest/sms/{country}/{company}/phone/{mobilenumber}", defaults: new { controller = "Sms", action = "PostSms" }); 

控制器:

 public HttpResponseMessage PostSms(string country, string company, string mobilenumber) { return Request.CreateResponse( HttpStatusCode.Created ); } 

当我在fiddler上运行这个post方法时:

 http://index.html/rest/sms/se/company/phone/46700101010/messages/out 

我收到了这个回复:

在此处输入图像描述

但我希望它能够向我展示加号。

IIS阻止加号在URL路径元素中。

要禁用此function,请在web.config

      

编码+

用以下内容替换您的Feed输入:

HTTP://index.html/rest/sms/se/company/phone/%2B46700101010/messages/out

另请参阅: AJAX POST和Plus Sign(+) – 如何编码?

http://www.google.com/search?q=foo%2Bbar

这是我们在url中添加参数时遇到的常见exception。 在这里,您可以了解OP的内容以及稍后运行时可能需要的内容

您可以使用许多选项,您可以在java脚本文件中使用编码

 encodeURIComponent(); 

如果您想在url中添加任何特殊字符,也可以轻松自如. 然后只需在web.config中设置属性relaxedUrlToFileSystemMapping

   

或者您可以使用web.config requestPathInvalidCharacters添加或删除一些要阻止/允许的字符