【问题标题】:How to capture multiple URL parameters / segments?如何捕获多个 URL 参数/段?
【发布时间】:2017-03-25 17:30:39
【问题描述】:

给定一个像http://test.com/abc/xyz/1/2/3 这样的网址,我如何检索abc/ 之后的所有网址段,所以结果值将是["xyz","1","2","3]

【问题讨论】:

    标签: scotty haskell-wai


    【解决方案1】:

    如果将来有人偶然发现这个问题,我已经设法解决它:

    processParams :: String -> Request -> Maybe [Param]
    processParams s x  = do
      case (params', isPrefix) of
        (_:paramsxs, True) -> return $ fmap (flip (,) $ "") paramsxs
        _  -> Nothing
        where
          isPrefix = s `isPrefixOf` (convertString path) :: Bool
          path = rawPathInfo x
          params' = fmap convertString $ decodePathSegments path
    

    并使用function 函数:

    get (function $ processParams "/comparePackage") $ comparePackageHandler
    

    【讨论】:

      猜你喜欢
      • 2020-12-06
      • 2017-01-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-12-12
      • 2021-09-28
      • 2016-12-17
      • 1970-01-01
      相关资源
      最近更新 更多