2014-09-30 102 views
12

我正在使用一個asp.net web api項目,並且我必須通過一個帖子傳遞一個手機號碼。但我無法返回加號。+(加號)登錄Web API路由

我的路線:

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); 
} 

當我運行上的提琴手這個帖子方法:

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

我得到這樣的響應:

enter image description here

但我希望它能夠給我看加號。

回答

0

這是我們在url中添加參數時遇到的常見異常。在這裏,你可以有你的OP就是一個暗示,你可能需要的東西在以後的運行

你可以有很多選擇,作爲+你可以在你的Java腳本文件中使用

encodeURIComponent(); 

而且也編碼你放心,如果你想在你的網址添加任何特殊字符,如一個.然後簡單地設置屬性relaxedUrlToFileSystemMapping在你的web.config

<system.web> 
<httpRuntime relaxedUrlToFileSystemMapping="true" /> 

或者你也可以添加或刪除某些字符來阻止/允許使用requestPathInvalidCharactersweb.config

<httpRuntime requestPathInvalidCharacters="&lt;,&gt;,*,%,&amp;,:,\,?"/> 
+0

這是一個WebAPI問題。 – Ofiris 2014-10-01 11:00:24

+0

'relaxedUrlToFileSystemMapping'禁止的字符列表是'<, >,:,,,/,\,|,?和*','requestPathInvalidCharacters'的默認值是'<, >,*,%,&,:, 「這些都不會對加號產生影響,據我所知。 – RickNZ 2015-01-30 02:50:44

14

IIS防止加跡象從URL路徑元素之中。冰山

<system.webServer> 
    <security> 
     <requestFiltering allowDoubleEscaping="true" /> 
    </security> 
</system.webServer>