Passing double/float through URL to Web Api query string

…衆ロ難τιáo~ 提交于 2019-12-14 03:17:00

问题


I got a Web Api project, and I want to call a api controller through this URL:

Http://localhost:3030/GetByCoordinates/[[0,1],[1,1],[1,0],[0,0]]

It works fine, but when I try to add a double number (like 1.1 instead of 1) the browser throws 404 not found exception, because the dot make it look like another address.

How can i handle doubles ?


回答1:


Try adding '/' at the end of the URL, e.g.

Http://localhost:3030/GetByCoordinates/[[0,1],[1,1.1],[1,0],[0,0]]/

Reference: Why is my Web API method with double args not getting called?




回答2:


This isn't strictly the query string, but unless you can configure your MVC project (or, more specifcally, probably IIS) to allow/manage certain mappings (or not to manage them, in a given case perhaps) then you should be able to translate the character from one form to another.

That is, you could swap periods out for %2E, and swap them back in on the server side.



来源:https://stackoverflow.com/questions/15528819/passing-double-float-through-url-to-web-api-query-string

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!